Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp11201030ybl; Fri, 27 Dec 2019 09:27:01 -0800 (PST) X-Google-Smtp-Source: APXvYqzIfMkoeOMVyJ3MjjIUIp3WvvVRIN2NpbHJ99MS6kDO19y56mGyMwnpX5a2Mv9zJpEEjKHH X-Received: by 2002:aca:be56:: with SMTP id o83mr3981130oif.25.1577467621079; Fri, 27 Dec 2019 09:27:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577467621; cv=none; d=google.com; s=arc-20160816; b=i35WX7TtAr4mvGKDwg/aVmYeEjURVmhC/Isg8xEMdxPW+UkNpGPiPZlELen9WTTwHP V/1tA56ZCKY+uMLqlpbhswIqE5nokq+4Tw+uOudz6g56sh9go8xhAB9R4x/qBhv3iTYl VgjUT4a6icRe1OoplIufK4/5dTd3nkAJxQwovv9bqNdkDHuVQ7Xnh1Ni015csMNSASd7 DehIWElKuNJGTgp/JxjVoT0/VQegoEbItDubPj4a/SaZxKIFGAJwO0iuBvetDcaYd/4L Np0nANKlfsyD8lZF+ma+7WyCSuNpEMD/CC8lBVxZfelSs/cws0cjuzbZJWvdP1I93Oa+ 8hDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date:dkim-signature; bh=6BagKGK8+pZSqwaMw/HELL5MlEA5rUbPb85VxpNXUsU=; b=yGzvUXo8VfJ1wRXqz3uDOlkCOioMUG5cmNw32bXKh5qBWnbgu3r42GBbk5Y/GL+Yp2 vqO+N18GO6v+8whqrmEy73z4pVdaXOOf1LspmD8cI5hfHuIUMnuvGEiyilT8a+uX2y/9 CJ6Mm/1TlCOyotTqd387OPPrFX0qJvfj2S/UmlJU/o8g1sw+5ZFqdi42rQgQtnTCwEsY Ue6NVZrkMafeQqn61a5yJUgaPfhBrHtdAGsGmAQYoQTrMu6ozAm3BrILvW+sJ3Ze9/d0 UgBHt5FFVTHqGsdME+OSkzD3BdlZyvuorvnakCdXfz/+ZQMr2AuJ8dQpeBSupQRP7nrd 25Zg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DcFOCXg7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h14si12762735oie.98.2019.12.27.09.26.48; Fri, 27 Dec 2019 09:27:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DcFOCXg7; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727029AbfL0RYX (ORCPT + 99 others); Fri, 27 Dec 2019 12:24:23 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:36664 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726527AbfL0RYU (ORCPT ); Fri, 27 Dec 2019 12:24:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1577467458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6BagKGK8+pZSqwaMw/HELL5MlEA5rUbPb85VxpNXUsU=; b=DcFOCXg7tvjzKXO/4xT6mJhMyKoVI+MphdTK4X0+Ffe7AAJJD44bK8KpByEhJnKzScEJBN 3f/5S+48ez2V410e1M8RUuwx0EDO0wHT2DzhfnkAv/oExGl4zZiW4Ge5uBFW4XGhCVk6jf z+U8CZnKIRNbdMX87vBkA9b3O/lpDWA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-264-1y8vaMnpOPeT0R7BGJ8Y8A-1; Fri, 27 Dec 2019 12:24:14 -0500 X-MC-Unique: 1y8vaMnpOPeT0R7BGJ8Y8A-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81F8A107ACC5; Fri, 27 Dec 2019 17:24:13 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7712360BFB; Fri, 27 Dec 2019 17:24:13 +0000 (UTC) Received: from zmail21.collab.prod.int.phx2.redhat.com (zmail21.collab.prod.int.phx2.redhat.com [10.5.83.24]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6A6B318089C8; Fri, 27 Dec 2019 17:24:13 +0000 (UTC) Date: Fri, 27 Dec 2019 12:24:13 -0500 (EST) From: Vladis Dronov To: Richard Cochran Cc: linux-fsdevel@vger.kernel.org, Alexander Viro , Al Viro , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Message-ID: <1031316500.2657655.1577467453350.JavaMail.zimbra@redhat.com> In-Reply-To: <20191227150218.GA1435@localhost> References: <20191208195340.GX4203@ZenIV.linux.org.uk> <20191227022627.24476-1-vdronov@redhat.com> <20191227150218.GA1435@localhost> Subject: Re: [PATCH v2] ptp: fix the race between the release of ptp_clock and cdev MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [194.228.13.70, 10.4.196.16, 10.5.100.50, 10.4.195.23] Thread-Topic: fix the race between the release of ptp_clock and cdev Thread-Index: irWUFwtSG/M8AhEHYaeQCeWyBgqSgA== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, Richard, Thank you for the review! > > + * @dev: Pointer to the initialized device. Caller must provide > > + * 'release' filed > > field Indeed. *sigh* Nothing is ideal. Let's hope a maintainer could fix it if this is approved. Best regards, Vladis Dronov | Red Hat, Inc. | The Core Kernel | Senior Software Engineer ----- Original Message ----- > From: "Richard Cochran" > To: "Vladis Dronov" > Cc: linux-fsdevel@vger.kernel.org, "Alexander Viro" , "Al Viro" , > netdev@vger.kernel.org, linux-kernel@vger.kernel.org > Sent: Friday, December 27, 2019 4:02:19 PM > Subject: Re: [PATCH v2] ptp: fix the race between the release of ptp_clock and cdev > > On Fri, Dec 27, 2019 at 03:26:27AM +0100, Vladis Dronov wrote: > > Here cdev is embedded in posix_clock which is embedded in ptp_clock. > > The race happens because ptp_clock's lifetime is controlled by two > > refcounts: kref and cdev.kobj in posix_clock. This is wrong. > > > > Make ptp_clock's sysfs device a parent of cdev with cdev_device_add() > > created especially for such cases. This way the parent device with its > > ptp_clock is not released until all references to the cdev are released. > > This adds a requirement that an initialized but not exposed struct > > device should be provided to posix_clock_register() by a caller instead > > of a simple dev_t. > > > > This approach was adopted from the commit 72139dfa2464 ("watchdog: Fix > > the race between the release of watchdog_core_data and cdev"). See > > details of the implementation in the commit 233ed09d7fda ("chardev: add > > helper function to register char devs with a struct device"). > > Thanks for digging into this! > > Acked-by: Richard Cochran > > > /** > > * posix_clock_register() - register a new clock > > - * @clk: Pointer to the clock. Caller must provide 'ops' and 'release' > > - * @devid: Allocated device id > > + * @clk: Pointer to the clock. Caller must provide 'ops' field > > + * @dev: Pointer to the initialized device. Caller must provide > > + * 'release' filed > > field > > Thanks, > Richard