Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp8728307rwd; Tue, 20 Jun 2023 20:30:41 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5h/PqCdIml0XAXcHeFBLW8ufv/NrSPaRo2NgcKMis6wYFnMkfO5ILuI+mig2Ykz/Mt+3Uo X-Received: by 2002:a05:6358:9dac:b0:12f:150b:dcfe with SMTP id d44-20020a0563589dac00b0012f150bdcfemr7998918rwo.6.1687318240877; Tue, 20 Jun 2023 20:30:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687318240; cv=none; d=google.com; s=arc-20160816; b=j/KpT0UarzS3rsdtu240BGd4MBkHEWWj/WvCa4Geaf6+wG5JiQK7lBkS5o6voPD6oJ vpQzv368b51937jTiHiULw3w3vIrkXbgSgM3EYgrqzwrpIa0ttsiC/OSYktqG0kbe1PW iUw2RQUKuwWiZyX8nnMQh6jpeNtq2cFSOA4+HHlcoVrvd3D8RKkNXoaC3qWpZbBky30F Bh5sMc6W5Uh8rUmQxzp82F4meVUYKhoIjQ8NLcRM8sJ1mf2nd83FFgiNCISu5ni73aQB yCIHPkd3pKY2t/euV6jh70oVe794zVkhhDX5CQhu/6coEXR2csG5H9rhFHvdIZnM6QEc qr1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=elhQiYgc/jirqX3wBHnMttM8AI1mnDD23NxVQeQhyPE=; b=BUx3ghdUOg/uST+IAyqjG7EqGitvNuzqEvw3ZAxyjgLEGzibWGe9DD3QoKdQSfOHEn YawsMbdWKgcq1aOLGKaDOfh916Hm0jRrDXT6Midy080e4IPLZPxvUpA24+2+Z/hLqCfW uMesafXjLpceULtXcr8akZdZ0lJd6YViodPmLvXbGqiYkgurvxl6S41L3I2clx7tw9a1 a8334LJfNw/oMgI9JiyYDKSXMGQTeb3Aix0NR20XHTZb6Z2UHGHWHSkhS0r34QXUTAdp J06QNoESXbYb88Is8iwBNdo+1Qjdm+tdiQK9j6d5WfHl4sCajxgz+a4pIofGTlqOZCB/ lK6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b="d/wmJgV+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e22-20020a633716000000b0054f8da23807si3306254pga.91.2023.06.20.20.30.26; Tue, 20 Jun 2023 20:30:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@yandex.ru header.s=mail header.b="d/wmJgV+"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbjFUCyV (ORCPT + 99 others); Tue, 20 Jun 2023 22:54:21 -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 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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.