linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ptp: free ptp clock properly
@ 2020-03-09 17:22 Andrea Righi
  2020-03-10  2:57 ` Richard Cochran
  2020-04-03 13:34 ` Vladis Dronov
  0 siblings, 2 replies; 5+ messages in thread
From: Andrea Righi @ 2020-03-09 17:22 UTC (permalink / raw)
  To: Richard Cochran, Vladis Dronov; +Cc: David S. Miller, netdev, linux-kernel

There is a bug in ptp_clock_unregister() where pps_unregister_source()
can free up resources needed by posix_clock_unregister() to properly
destroy a related sysfs device.

Fix this by calling pps_unregister_source() in ptp_clock_release().

See also:
commit 75718584cb3c ("ptp: free ptp device pin descriptors properly").

BugLink: https://bugs.launchpad.net/bugs/1864754
Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and cdev")
Tested-by: Piotr Morgwai Kotarbiński <foss@morgwai.pl>
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
---

v2: move pps_unregister_source() to ptp_clock_release(), instead of
    posix_clock_unregister(), that would just introduce a resource leak

 drivers/ptp/ptp_clock.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
index ac1f2bf9e888..468286ef61ad 100644
--- a/drivers/ptp/ptp_clock.c
+++ b/drivers/ptp/ptp_clock.c
@@ -170,6 +170,9 @@ static void ptp_clock_release(struct device *dev)
 {
 	struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev);
 
+	/* Release the clock's resources. */
+	if (ptp->pps_source)
+		pps_unregister_source(ptp->pps_source);
 	ptp_cleanup_pin_groups(ptp);
 	mutex_destroy(&ptp->tsevq_mux);
 	mutex_destroy(&ptp->pincfg_mux);
@@ -298,11 +301,6 @@ int ptp_clock_unregister(struct ptp_clock *ptp)
 		kthread_cancel_delayed_work_sync(&ptp->aux_work);
 		kthread_destroy_worker(ptp->kworker);
 	}
-
-	/* Release the clock's resources. */
-	if (ptp->pps_source)
-		pps_unregister_source(ptp->pps_source);
-
 	posix_clock_unregister(&ptp->clock);
 
 	return 0;
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ptp: free ptp clock properly
  2020-03-09 17:22 [PATCH v2] ptp: free ptp clock properly Andrea Righi
@ 2020-03-10  2:57 ` Richard Cochran
  2020-04-03 13:34 ` Vladis Dronov
  1 sibling, 0 replies; 5+ messages in thread
From: Richard Cochran @ 2020-03-10  2:57 UTC (permalink / raw)
  To: Andrea Righi; +Cc: Vladis Dronov, David S. Miller, netdev, linux-kernel

On Mon, Mar 09, 2020 at 06:22:38PM +0100, Andrea Righi wrote:
> There is a bug in ptp_clock_unregister() where pps_unregister_source()
> can free up resources needed by posix_clock_unregister() to properly
> destroy a related sysfs device.

This text is inadequate.  It does not identify the problem.  What
resources?  Which related device?

> Fix this by calling pps_unregister_source() in ptp_clock_release().

This statement is redundant, as we can see that from the patch itself.
Instead of saying WHAT the patch does, please explain WHY that fixes
the issue (which, as I said, you still need to identify).

Thanks,
Richard


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ptp: free ptp clock properly
  2020-03-09 17:22 [PATCH v2] ptp: free ptp clock properly Andrea Righi
  2020-03-10  2:57 ` Richard Cochran
@ 2020-04-03 13:34 ` Vladis Dronov
  2020-04-07  9:34   ` Andrea Righi
  1 sibling, 1 reply; 5+ messages in thread
From: Vladis Dronov @ 2020-04-03 13:34 UTC (permalink / raw)
  To: Andrea Righi, Colin Ian King
  Cc: Richard Cochran, David S. Miller, netdev, linux-kernel

Hello, Andrea, Colin, all,

This fix is really not needed, as its creation is based on the assumption
that the Ubuntu kernel 5.3.0-40-generic has the upstream commit 75718584cb3c,
which is the real fix to this crash.

> > > I would guess that a kernel in question (5.3.0-40-generic) has the commit
> > > a33121e5487b but does not have the commit 75718584cb3c, which should be
> > > exactly fixing a docking station disconnect crash. Could you please,
> > > check this?
> >
> > Unfortunately the kernel in question already has 75718584cb3c:
> > https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic/commit/?h=hwe&id=c71b774732f997ef38ed7bd62e73891a01f2bbfe

Apologies, but the assumption above is not correct, 5.3.0-40-generic does
not have 75718584cb3c. If it had 75718584cb3c it would be a fix and the ptp-related
crash (described in https://bugs.launchpad.net/bugs/1864754) would not happen.

This way https://lists.ubuntu.com/archives/kernel-team/2020-March/108562.html fix
is not really needed.

Best regards,
Vladis Dronov | Red Hat, Inc. | The Core Kernel | Senior Software Engineer

----- Original Message -----
> From: "Andrea Righi" <andrea.righi@canonical.com>
> To: "Richard Cochran" <richardcochran@gmail.com>, "Vladis Dronov" <vdronov@redhat.com>
> Cc: "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
> Sent: Monday, March 9, 2020 6:22:38 PM
> Subject: [PATCH v2] ptp: free ptp clock properly
> 
> There is a bug in ptp_clock_unregister() where pps_unregister_source()
> can free up resources needed by posix_clock_unregister() to properly
> destroy a related sysfs device.
> 
> Fix this by calling pps_unregister_source() in ptp_clock_release().
> 
> See also:
> commit 75718584cb3c ("ptp: free ptp device pin descriptors properly").
> 
> BugLink: https://bugs.launchpad.net/bugs/1864754
> Fixes: a33121e5487b ("ptp: fix the race between the release of ptp_clock and
> cdev")
> Tested-by: Piotr Morgwai Kotarbiński <foss@morgwai.pl>
> Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
> ---
> 
> v2: move pps_unregister_source() to ptp_clock_release(), instead of
>     posix_clock_unregister(), that would just introduce a resource leak
> 
>  drivers/ptp/ptp_clock.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/ptp/ptp_clock.c b/drivers/ptp/ptp_clock.c
> index ac1f2bf9e888..468286ef61ad 100644
> --- a/drivers/ptp/ptp_clock.c
> +++ b/drivers/ptp/ptp_clock.c
> @@ -170,6 +170,9 @@ static void ptp_clock_release(struct device *dev)
>  {
>  	struct ptp_clock *ptp = container_of(dev, struct ptp_clock, dev);
>  
> +	/* Release the clock's resources. */
> +	if (ptp->pps_source)
> +		pps_unregister_source(ptp->pps_source);
>  	ptp_cleanup_pin_groups(ptp);
>  	mutex_destroy(&ptp->tsevq_mux);
>  	mutex_destroy(&ptp->pincfg_mux);
> @@ -298,11 +301,6 @@ int ptp_clock_unregister(struct ptp_clock *ptp)
>  		kthread_cancel_delayed_work_sync(&ptp->aux_work);
>  		kthread_destroy_worker(ptp->kworker);
>  	}
> -
> -	/* Release the clock's resources. */
> -	if (ptp->pps_source)
> -		pps_unregister_source(ptp->pps_source);
> -
>  	posix_clock_unregister(&ptp->clock);
>  
>  	return 0;
> --
> 2.25.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ptp: free ptp clock properly
  2020-04-03 13:34 ` Vladis Dronov
@ 2020-04-07  9:34   ` Andrea Righi
  2020-04-07 10:05     ` Vladis Dronov
  0 siblings, 1 reply; 5+ messages in thread
From: Andrea Righi @ 2020-04-07  9:34 UTC (permalink / raw)
  To: Vladis Dronov
  Cc: Piotr Morgwai Kotarbiński, Colin Ian King, Richard Cochran,
	David S. Miller, netdev, linux-kernel

On Fri, Apr 03, 2020 at 09:34:14AM -0400, Vladis Dronov wrote:
> Hello, Andrea, Colin, all,
> 
> This fix is really not needed, as its creation is based on the assumption
> that the Ubuntu kernel 5.3.0-40-generic has the upstream commit 75718584cb3c,
> which is the real fix to this crash.
> 
> > > > I would guess that a kernel in question (5.3.0-40-generic) has the commit
> > > > a33121e5487b but does not have the commit 75718584cb3c, which should be
> > > > exactly fixing a docking station disconnect crash. Could you please,
> > > > check this?
> > >
> > > Unfortunately the kernel in question already has 75718584cb3c:
> > > https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic/commit/?h=hwe&id=c71b774732f997ef38ed7bd62e73891a01f2bbfe
> 
> Apologies, but the assumption above is not correct, 5.3.0-40-generic does
> not have 75718584cb3c. If it had 75718584cb3c it would be a fix and the ptp-related
> crash (described in https://bugs.launchpad.net/bugs/1864754) would not happen.
> 
> This way https://lists.ubuntu.com/archives/kernel-team/2020-March/108562.html fix
> is not really needed.

Hi Vladis,

for the records, I repeated the tests with a lot of help from the bug
reporter (Morgwai, added in cc), this time making sure we were using the
same kernels.

I confirm that my fix is not really needed as you correctly pointed out.
Thanks for looking into this and sorry for the noise! :)

-Andrea

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] ptp: free ptp clock properly
  2020-04-07  9:34   ` Andrea Righi
@ 2020-04-07 10:05     ` Vladis Dronov
  0 siblings, 0 replies; 5+ messages in thread
From: Vladis Dronov @ 2020-04-07 10:05 UTC (permalink / raw)
  To: Andrea Righi
  Cc: Piotr Morgwai Kotarbiński, Colin Ian King, netdev, linux-kernel

Hello,

----- Original Message -----
> From: "Andrea Righi" <andrea.righi@canonical.com>
> To: "Vladis Dronov" <vdronov@redhat.com>
> Cc: "Piotr Morgwai Kotarbiński" <morgwai@morgwai.pl>, "Colin Ian King" <colin.king@canonical.com>, "Richard Cochran"
> <richardcochran@gmail.com>, "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org,
> linux-kernel@vger.kernel.org
> Sent: Tuesday, April 7, 2020 11:34:22 AM
> Subject: Re: [PATCH v2] ptp: free ptp clock properly
> 
> On Fri, Apr 03, 2020 at 09:34:14AM -0400, Vladis Dronov wrote:
> > Hello, Andrea, Colin, all,
> > 
> > This fix is really not needed, as its creation is based on the assumption
> > that the Ubuntu kernel 5.3.0-40-generic has the upstream commit
> > 75718584cb3c,
> > which is the real fix to this crash.
> > 
> > > > > I would guess that a kernel in question (5.3.0-40-generic) has the
> > > > > commit
> > > > > a33121e5487b but does not have the commit 75718584cb3c, which should
> > > > > be
> > > > > exactly fixing a docking station disconnect crash. Could you please,
> > > > > check this?
> > > >
> > > > Unfortunately the kernel in question already has 75718584cb3c:
> > > > https://git.launchpad.net/~ubuntu-kernel/ubuntu/+source/linux/+git/bionic/commit/?h=hwe&id=c71b774732f997ef38ed7bd62e73891a01f2bbfe
> > 
> > Apologies, but the assumption above is not correct, 5.3.0-40-generic does
> > not have 75718584cb3c. If it had 75718584cb3c it would be a fix and the
> > ptp-related
> > crash (described in https://bugs.launchpad.net/bugs/1864754) would not
> > happen.
> > 
> > This way
> > https://lists.ubuntu.com/archives/kernel-team/2020-March/108562.html fix
> > is not really needed.
> 
> Hi Vladis,
> 
> for the records, I repeated the tests with a lot of help from the bug
> reporter (Morgwai, added in cc), this time making sure we were using the
> same kernels.
> 
> I confirm that my fix is not really needed as you correctly pointed out.
> Thanks for looking into this and sorry for the noise! :)

Hei, great! Thank you for updating. I'm happy this situation has resolved
properly!

> 
> -Andrea
> 

Best regards,
Vladis Dronov | Red Hat, Inc. | The Core Kernel | Senior Software Engineer


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-04-07 10:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-09 17:22 [PATCH v2] ptp: free ptp clock properly Andrea Righi
2020-03-10  2:57 ` Richard Cochran
2020-04-03 13:34 ` Vladis Dronov
2020-04-07  9:34   ` Andrea Righi
2020-04-07 10:05     ` Vladis Dronov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).