From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69F5AEB64D8 for ; Wed, 21 Jun 2023 02:54:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbjFUCyW (ORCPT ); Tue, 20 Jun 2023 22:54:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229470AbjFUCyU (ORCPT ); Tue, 20 Jun 2023 22:54:20 -0400 Received: from forward501b.mail.yandex.net (forward501b.mail.yandex.net [178.154.239.145]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 917851704; Tue, 20 Jun 2023 19:54:18 -0700 (PDT) Received: from mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net [IPv6:2a02:6b8:c14:2481:0:640:e0:0]) by forward501b.mail.yandex.net (Yandex) with ESMTP id 036065F01D; Wed, 21 Jun 2023 05:54:16 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id DsXQr41DViE0-SPDjKbks; Wed, 21 Jun 2023 05:54:15 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1687316055; bh=elhQiYgc/jirqX3wBHnMttM8AI1mnDD23NxVQeQhyPE=; h=From:In-Reply-To:Cc:Date:References:To:Subject:Message-ID; b=d/wmJgV+Kb8xW7NsO5+V8bCyHSYmrnnfmeiuJWLSpvJXZ4DBbqSZeZt4zgbDSCVTq SZ8PBm9LbeD7Lf7kDGuUqT4QtVhtuzEtIXXssbOYqNeaC4sATlhJziXs2qjhlEoZ+A 1H4d6VRu6sG3IJcu3c51ifBApQuFx8lz7Z8enlKY= Authentication-Results: mail-nwsmtp-smtp-production-main-10.sas.yp-c.yandex.net; dkim=pass header.i=@yandex.ru Message-ID: Date: Wed, 21 Jun 2023 07:54:13 +0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Subject: Re: [PATCH 2/3] fd/locks: allow get the lock owner by F_OFD_GETLK Content-Language: en-US To: Matthew Wilcox Cc: Jeff Layton , linux-kernel@vger.kernel.org, Chuck Lever , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org References: <5f644a24-90b5-a02f-b593-49336e8e0f5a@yandex.ru> <2eb8566726e95a01536b61a3b8d0343379092b94.camel@kernel.org> <08612562-d2d7-a931-0c40-c401fff772c7@yandex.ru> From: stsp In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 20.06.2023 22:05, Matthew Wilcox пишет: >> Does this mean, by any chance, that the >> recipient actually owns an fd before >> recvmsg() is done? > no, it's not in their fd table. they don't own it. OK, thanks for showing this pathological case. Let me just note that this changes nothing at all. :) The important thing to note here is that any lock query is race-prone: locks can come and go at any time. So if you need some sequence of operations, you need to employ some global locking for that. I use flock(LOCK_EX) on the same fd, before doing F_OFD_GETLK, and I do flock(LOCK_UN) only when the entire sequence of operations is completed. And I do the same on an F_OFD_SETLK's side to guarantee the atomicity. You can't do it otherwise, it would be race-prone. So given the above, the only thing we need for l_pid consistency is for the "donor" process to put LOCK_EX on an fd before doing SCM_RIGHTS, and the recipient should do LOCK_UN. Then the other side, which also uses LOCK_EX, will never see the owner-less state. And as for the kernel's POV, l_pid should be set to -1 only when there is no owner, like in an example you mentioned.