From: David Woodhouse <dwmw2@infradead.org>
To: Jakub Kicinski <kuba@kernel.org>, itazur@amazon.com
Cc: graf@amazon.de, itazur@amazon.co.uk, conor+dt@kernel.org,
devicetree@vger.kernel.org, xmarcalx@amazon.co.uk,
linux-kernel@vger.kernel.org, edumazet@google.com,
robh@kernel.org, richardcochran@gmail.com,
andrew+netdev@lunn.ch, mzxreary@0pointer.de, pabeni@redhat.com,
netdev@vger.kernel.org, krzk+dt@kernel.org, davem@davemloft.net,
mail@bchalios.io
Subject: Re: [v6,2/7] ptp: vmclock: support device notifications
Date: Fri, 23 Jan 2026 12:16:46 -0800 [thread overview]
Message-ID: <f663dbfff1568d8924a2a3b8fbd6532b97f54b68.camel@infradead.org> (raw)
In-Reply-To: <20260123031133.3059291-2-kuba@kernel.org>
[-- Attachment #1: Type: text/plain, Size: 3813 bytes --]
On Thu, 2026-01-22 at 19:11 -0800, Jakub Kicinski wrote:
>
> > + status = acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY,
> > + vmclock_acpi_notification_handler,
> > + dev);
>
> Since acpi_install_notify_handler() is called here, should there be a
> corresponding acpi_remove_notify_handler() in vmclock_remove()? Currently
> the handler remains registered after device removal, which could lead to
> a use-after-free if the hypervisor sends a notification after the driver
> state has been freed.
>
> [ ... ]
>
> > @@ -549,6 +653,11 @@ static int vmclock_probe(struct platform_device *pdev)
> > if (ret)
> > return ret;
> >
> > + init_waitqueue_head(&st->disrupt_wait);
> > + ret = vmclock_setup_notification(dev, st);
> > + if (ret)
> > + return ret;
>
> [ ... ]
>
> > @@ -581,6 +690,8 @@ static int vmclock_probe(struct platform_device *pdev)
> > return -ENODEV;
> > }
> >
> > + dev->driver_data = st;
>
> Is there a race window here? The ACPI notification handler is installed
> in vmclock_setup_notification() which runs earlier in vmclock_probe(),
> but the handler accesses device->driver_data. If the hypervisor sends a
> notification between vmclock_setup_notification() and this assignment,
> vmclock_acpi_notification_handler() would dereference NULL or garbage.
>
> I see this is fixed later in the series by commit 47fdd294385e which
> moves dev->driver_data = st before vmclock_setup_notification().
With the incremental diff below, I've fixed both of these in
https://git.infradead.org/?p=users/dwmw2/linux.git;a=shortlog;h=refs/heads/vmclock
Takahiro and Babis have the test environment set up to actually
exercise the notifications, so I'll let one of them actually do the
testing and repost v7.
Takahiro, please remember to add your own 'Signed-off-by:' as you do.
Thanks!
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -490,17 +490,6 @@ static const struct file_operations vmclock_miscdev_fops = {
/* module operations */
-static void vmclock_remove(void *data)
-{
- struct vmclock_state *st = data;
-
- if (st->ptp_clock)
- ptp_clock_unregister(st->ptp_clock);
-
- if (st->miscdev.minor != MISC_DYNAMIC_MINOR)
- misc_deregister(&st->miscdev);
-}
-
#if IS_ENABLED(CONFIG_ACPI)
static acpi_status vmclock_acpi_resources(struct acpi_resource *ares, void *data)
{
@@ -636,6 +625,32 @@ static int vmclock_setup_notification(struct device *dev,
return vmclock_setup_of_notification(dev);
}
+static void vmclock_remove(void *data)
+{
+ struct device *dev = data;
+ struct vmclock_state *st = dev->driver_data;
+
+ if (!st) {
+ dev_err(dev, "vmclock_remove() called with NULL driver_data");
+ return;
+ }
+
+#if IS_ENABLED(CONFIG_ACPI)
+ if (has_acpi_companion(dev))
+ acpi_remove_notify_handler(ACPI_COMPANION(dev)->handle,
+ ACPI_DEVICE_NOTIFY,
+ vmclock_acpi_notification_handler);
+#endif
+
+ if (st->ptp_clock)
+ ptp_clock_unregister(st->ptp_clock);
+
+ if (st->miscdev.minor != MISC_DYNAMIC_MINOR)
+ misc_deregister(&st->miscdev);
+
+ dev->driver_data = NULL;
+}
+
static void vmclock_put_idx(void *data)
{
struct vmclock_state *st = data;
@@ -701,12 +716,13 @@ static int vmclock_probe(struct platform_device *pdev)
st->miscdev.minor = MISC_DYNAMIC_MINOR;
- ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, st);
+ init_waitqueue_head(&st->disrupt_wait);
+ dev->driver_data = st;
+
+ ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, dev);
if (ret)
return ret;
- init_waitqueue_head(&st->disrupt_wait);
- dev->driver_data = st;
ret = vmclock_setup_notification(dev, st);
if (ret)
return ret;
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
next prev parent reply other threads:[~2026-01-23 20:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-21 14:33 [PATCH v6 0/7] ptp: vmclock: Add VM generation counter and ACPI notification Takahiro Itazuri
2026-01-21 14:33 ` [PATCH v6 1/7] ptp: vmclock: add vm generation counter Takahiro Itazuri
2026-01-21 14:33 ` [PATCH v6 2/7] ptp: vmclock: support device notifications Takahiro Itazuri
2026-01-23 3:11 ` [v6,2/7] " Jakub Kicinski
2026-01-23 20:16 ` David Woodhouse [this message]
2026-01-21 14:33 ` [PATCH v6 3/7] dt-bindings: ptp: Add amazon,vmclock Takahiro Itazuri
2026-01-21 14:33 ` [PATCH v6 4/7] ptp: ptp_vmclock: Add device tree support Takahiro Itazuri
2026-01-21 14:33 ` [PATCH v6 5/7] ptp: ptp_vmclock: add 'VMCLOCK' to ACPI device match Takahiro Itazuri
2026-01-21 14:33 ` [PATCH v6 6/7] ptp: ptp_vmclock: remove dependency on CONFIG_ACPI Takahiro Itazuri
2026-01-21 14:33 ` [PATCH v6 7/7] ptp: ptp_vmclock: return TAI not UTC Takahiro Itazuri
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f663dbfff1568d8924a2a3b8fbd6532b97f54b68.camel@infradead.org \
--to=dwmw2@infradead.org \
--cc=andrew+netdev@lunn.ch \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=graf@amazon.de \
--cc=itazur@amazon.co.uk \
--cc=itazur@amazon.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mail@bchalios.io \
--cc=mzxreary@0pointer.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=robh@kernel.org \
--cc=xmarcalx@amazon.co.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®