* [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling
@ 2025-02-06 17:45 Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage Thomas Weißschuh
` (6 more replies)
0 siblings, 7 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-06 17:45 UTC (permalink / raw)
To: David Woodhouse, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, Thomas Weißschuh,
stable
Some error handling issues I noticed while looking at the code.
Only compile-tested.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
Thomas Weißschuh (4):
ptp: vmclock: Set driver data before its usage
ptp: vmclock: Don't unregister misc device if it was not registered
ptp: vmclock: Clean up miscdev and ptp clock through devres
ptp: vmclock: Remove goto-based cleanup logic
drivers/ptp/ptp_vmclock.c | 46 ++++++++++++++++++++--------------------------
1 file changed, 20 insertions(+), 26 deletions(-)
---
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
change-id: 20250206-vmclock-probe-57cbcb770925
Best regards,
--
Thomas Weißschuh <thomas.weissschuh@linutronix.de>
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
@ 2025-02-06 17:45 ` Thomas Weißschuh
2025-02-07 7:07 ` Mateusz Polchlopek
2025-02-06 17:45 ` [PATCH net-next 2/4] ptp: vmclock: Don't unregister misc device if it was not registered Thomas Weißschuh
` (5 subsequent siblings)
6 siblings, 1 reply; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-06 17:45 UTC (permalink / raw)
To: David Woodhouse, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, Thomas Weißschuh,
stable
If vmlock_ptp_register() fails during probing, vmclock_remove() is
called to clean up the ptp clock and misc device.
It uses dev_get_drvdata() to access the vmclock state.
However the driver data is not yet set at this point.
Assign the driver data earlier.
Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
drivers/ptp/ptp_vmclock.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index 0a2cfc8ad3c5408a87fd8fedeff274ab895de3dd..1920698ae6eba6abfff5b61afae1b047910026fd 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -524,6 +524,8 @@ static int vmclock_probe(struct platform_device *pdev)
goto out;
}
+ dev_set_drvdata(dev, st);
+
if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
le16_to_cpu(st->clk->version) != 1) {
@@ -587,8 +589,6 @@ static int vmclock_probe(struct platform_device *pdev)
(st->miscdev.minor && st->ptp_clock) ? ", " : "",
st->ptp_clock ? "PTP" : "");
- dev_set_drvdata(dev, st);
-
out:
return ret;
}
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 2/4] ptp: vmclock: Don't unregister misc device if it was not registered
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage Thomas Weißschuh
@ 2025-02-06 17:45 ` Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 3/4] ptp: vmclock: Clean up miscdev and ptp clock through devres Thomas Weißschuh
` (4 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-06 17:45 UTC (permalink / raw)
To: David Woodhouse, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, Thomas Weißschuh,
stable
vmclock_remove() tries to detect the successful registration of the misc
device based on the value of its minor value.
However that check is incorrect if the misc device registration was not
attempted in the first place.
Always initialize the minor number, so the check works properly.
Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
drivers/ptp/ptp_vmclock.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index 1920698ae6eba6abfff5b61afae1b047910026fd..82e6bef72b1b6edef7d891964c3f9c4546f6ddba 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -549,6 +549,8 @@ static int vmclock_probe(struct platform_device *pdev)
goto out;
}
+ st->miscdev.minor = MISC_DYNAMIC_MINOR;
+
/*
* If the structure is big enough, it can be mapped to userspace.
* Theoretically a guest OS even using larger pages could still
@@ -556,7 +558,6 @@ static int vmclock_probe(struct platform_device *pdev)
* cross that bridge if/when we come to it.
*/
if (le32_to_cpu(st->clk->size) >= PAGE_SIZE) {
- st->miscdev.minor = MISC_DYNAMIC_MINOR;
st->miscdev.fops = &vmclock_miscdev_fops;
st->miscdev.name = st->name;
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 3/4] ptp: vmclock: Clean up miscdev and ptp clock through devres
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 2/4] ptp: vmclock: Don't unregister misc device if it was not registered Thomas Weißschuh
@ 2025-02-06 17:45 ` Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 4/4] ptp: vmclock: Remove goto-based cleanup logic Thomas Weißschuh
` (3 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-06 17:45 UTC (permalink / raw)
To: David Woodhouse, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, Thomas Weißschuh
Most resources owned by the vmclock device are managed through devres.
Only the miscdev and ptp clock are managed manually.
This makes the code slightly harder to understand than necessary.
Switch them over to devres and remove the now unnecessary drvdata.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
drivers/ptp/ptp_vmclock.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index 82e6bef72b1b6edef7d891964c3f9c4546f6ddba..b7fa196975229cec6d27b34f7bb235c53b5b5732 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -420,10 +420,9 @@ static const struct file_operations vmclock_miscdev_fops = {
/* module operations */
-static void vmclock_remove(struct platform_device *pdev)
+static void vmclock_remove(void *data)
{
- struct device *dev = &pdev->dev;
- struct vmclock_state *st = dev_get_drvdata(dev);
+ struct vmclock_state *st = data;
if (st->ptp_clock)
ptp_clock_unregister(st->ptp_clock);
@@ -524,8 +523,6 @@ static int vmclock_probe(struct platform_device *pdev)
goto out;
}
- dev_set_drvdata(dev, st);
-
if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
le16_to_cpu(st->clk->version) != 1) {
@@ -551,6 +548,10 @@ 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);
+ if (ret)
+ goto out;
+
/*
* If the structure is big enough, it can be mapped to userspace.
* Theoretically a guest OS even using larger pages could still
@@ -573,7 +574,6 @@ static int vmclock_probe(struct platform_device *pdev)
if (IS_ERR(st->ptp_clock)) {
ret = PTR_ERR(st->ptp_clock);
st->ptp_clock = NULL;
- vmclock_remove(pdev);
goto out;
}
}
@@ -602,7 +602,6 @@ MODULE_DEVICE_TABLE(acpi, vmclock_acpi_ids);
static struct platform_driver vmclock_platform_driver = {
.probe = vmclock_probe,
- .remove = vmclock_remove,
.driver = {
.name = "vmclock",
.acpi_match_table = vmclock_acpi_ids,
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 4/4] ptp: vmclock: Remove goto-based cleanup logic
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
` (2 preceding siblings ...)
2025-02-06 17:45 ` [PATCH net-next 3/4] ptp: vmclock: Clean up miscdev and ptp clock through devres Thomas Weißschuh
@ 2025-02-06 17:45 ` Thomas Weißschuh
2025-02-07 5:43 ` [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Richard Cochran
` (2 subsequent siblings)
6 siblings, 0 replies; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-06 17:45 UTC (permalink / raw)
To: David Woodhouse, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, Thomas Weißschuh
vmclock_probe() uses an "out:" label to return from the function on
error. This indicates that some cleanup operation is necessary.
However the label does not do anything as all resources are managed
through devres, making the code slightly harder to read.
Remove the label and just return directly.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
---
drivers/ptp/ptp_vmclock.c | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index b7fa196975229cec6d27b34f7bb235c53b5b5732..26fcc1185ee72999a43842a59164498657799b1f 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -505,14 +505,13 @@ static int vmclock_probe(struct platform_device *pdev)
if (ret) {
dev_info(dev, "Failed to obtain physical address: %d\n", ret);
- goto out;
+ return ret;
}
if (resource_size(&st->res) < VMCLOCK_MIN_SIZE) {
dev_info(dev, "Region too small (0x%llx)\n",
resource_size(&st->res));
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
st->clk = devm_memremap(dev, st->res.start, resource_size(&st->res),
MEMREMAP_WB | MEMREMAP_DEC);
@@ -520,37 +519,34 @@ static int vmclock_probe(struct platform_device *pdev)
ret = PTR_ERR(st->clk);
dev_info(dev, "failed to map shared memory\n");
st->clk = NULL;
- goto out;
+ return ret;
}
if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
le16_to_cpu(st->clk->version) != 1) {
dev_info(dev, "vmclock magic fields invalid\n");
- ret = -EINVAL;
- goto out;
+ return -EINVAL;
}
ret = ida_alloc(&vmclock_ida, GFP_KERNEL);
if (ret < 0)
- goto out;
+ return ret;
st->index = ret;
ret = devm_add_action_or_reset(&pdev->dev, vmclock_put_idx, st);
if (ret)
- goto out;
+ return ret;
st->name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "vmclock%d", st->index);
- if (!st->name) {
- ret = -ENOMEM;
- goto out;
- }
+ if (!st->name)
+ return -ENOMEM;
st->miscdev.minor = MISC_DYNAMIC_MINOR;
ret = devm_add_action_or_reset(&pdev->dev, vmclock_remove, st);
if (ret)
- goto out;
+ return ret;
/*
* If the structure is big enough, it can be mapped to userspace.
@@ -564,7 +560,7 @@ static int vmclock_probe(struct platform_device *pdev)
ret = misc_register(&st->miscdev);
if (ret)
- goto out;
+ return ret;
}
/* If there is valid clock information, register a PTP clock */
@@ -574,15 +570,14 @@ static int vmclock_probe(struct platform_device *pdev)
if (IS_ERR(st->ptp_clock)) {
ret = PTR_ERR(st->ptp_clock);
st->ptp_clock = NULL;
- goto out;
+ return ret;
}
}
if (!st->miscdev.minor && !st->ptp_clock) {
/* Neither miscdev nor PTP registered */
dev_info(dev, "vmclock: Neither miscdev nor PTP available; not registering\n");
- ret = -ENODEV;
- goto out;
+ return -ENODEV;
}
dev_info(dev, "%s: registered %s%s%s\n", st->name,
@@ -590,8 +585,7 @@ static int vmclock_probe(struct platform_device *pdev)
(st->miscdev.minor && st->ptp_clock) ? ", " : "",
st->ptp_clock ? "PTP" : "");
- out:
- return ret;
+ return 0;
}
static const struct acpi_device_id vmclock_acpi_ids[] = {
--
2.48.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
` (3 preceding siblings ...)
2025-02-06 17:45 ` [PATCH net-next 4/4] ptp: vmclock: Remove goto-based cleanup logic Thomas Weißschuh
@ 2025-02-07 5:43 ` Richard Cochran
2025-02-07 7:13 ` Mateusz Polchlopek
2025-02-07 9:13 ` [PATCH net-next 5/4] ptp: vmclock: Add .owner to vmclock_miscdev_fops David Woodhouse
6 siblings, 0 replies; 12+ messages in thread
From: Richard Cochran @ 2025-02-07 5:43 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: David Woodhouse, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, David Woodhouse, netdev,
linux-kernel, stable
On Thu, Feb 06, 2025 at 06:45:00PM +0100, Thomas Weißschuh wrote:
> Some error handling issues I noticed while looking at the code.
>
> Only compile-tested.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
For the series:
Acked-by: Richard Cochran <richardcochran@gmail.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage
2025-02-06 17:45 ` [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage Thomas Weißschuh
@ 2025-02-07 7:07 ` Mateusz Polchlopek
0 siblings, 0 replies; 12+ messages in thread
From: Mateusz Polchlopek @ 2025-02-07 7:07 UTC (permalink / raw)
To: Thomas Weißschuh, David Woodhouse, Richard Cochran,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, stable
On 2/6/2025 6:45 PM, Thomas Weißschuh wrote:
> If vmlock_ptp_register() fails during probing, vmclock_remove() is
Typo: you missed 'c' in function name - vmclock_ptp_register
> called to clean up the ptp clock and misc device.
> It uses dev_get_drvdata() to access the vmclock state.
> However the driver data is not yet set at this point.
>
> Assign the driver data earlier.
>
> Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
> Cc: stable@vger.kernel.org
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> drivers/ptp/ptp_vmclock.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
> index 0a2cfc8ad3c5408a87fd8fedeff274ab895de3dd..1920698ae6eba6abfff5b61afae1b047910026fd 100644
> --- a/drivers/ptp/ptp_vmclock.c
> +++ b/drivers/ptp/ptp_vmclock.c
> @@ -524,6 +524,8 @@ static int vmclock_probe(struct platform_device *pdev)
> goto out;
> }
>
> + dev_set_drvdata(dev, st);
> +
> if (le32_to_cpu(st->clk->magic) != VMCLOCK_MAGIC ||
> le32_to_cpu(st->clk->size) > resource_size(&st->res) ||
> le16_to_cpu(st->clk->version) != 1) {
> @@ -587,8 +589,6 @@ static int vmclock_probe(struct platform_device *pdev)
> (st->miscdev.minor && st->ptp_clock) ? ", " : "",
> st->ptp_clock ? "PTP" : "");
>
> - dev_set_drvdata(dev, st);
> -
> out:
> return ret;
> }
>
Nice catch! The code looks good but please fix the typo in the
commit msg, as this may be misleading. When applied please add my:
Reviewed-by: Mateusz Polchlopek <mateusz.polchlopek@intel.com>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
` (4 preceding siblings ...)
2025-02-07 5:43 ` [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Richard Cochran
@ 2025-02-07 7:13 ` Mateusz Polchlopek
2025-02-07 9:10 ` David Woodhouse
2025-02-07 9:13 ` [PATCH net-next 5/4] ptp: vmclock: Add .owner to vmclock_miscdev_fops David Woodhouse
6 siblings, 1 reply; 12+ messages in thread
From: Mateusz Polchlopek @ 2025-02-07 7:13 UTC (permalink / raw)
To: Thomas Weißschuh, David Woodhouse, Richard Cochran,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: David Woodhouse, netdev, linux-kernel, stable
On 2/6/2025 6:45 PM, Thomas Weißschuh wrote:
> Some error handling issues I noticed while looking at the code.
>
> Only compile-tested.
>
> Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> ---
> Thomas Weißschuh (4):
> ptp: vmclock: Set driver data before its usage
> ptp: vmclock: Don't unregister misc device if it was not registered
> ptp: vmclock: Clean up miscdev and ptp clock through devres
> ptp: vmclock: Remove goto-based cleanup logic
>
> drivers/ptp/ptp_vmclock.c | 46 ++++++++++++++++++++--------------------------
> 1 file changed, 20 insertions(+), 26 deletions(-)
> ---
> base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> change-id: 20250206-vmclock-probe-57cbcb770925
>
> Best regards,
As those all are fixes and cleanups then I think it should be tagged to
net not net-next.
thanks
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling
2025-02-07 7:13 ` Mateusz Polchlopek
@ 2025-02-07 9:10 ` David Woodhouse
2025-02-07 9:25 ` Thomas Weißschuh
0 siblings, 1 reply; 12+ messages in thread
From: David Woodhouse @ 2025-02-07 9:10 UTC (permalink / raw)
To: Mateusz Polchlopek, Thomas Weißschuh, Richard Cochran,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: netdev, linux-kernel, stable, Mohamed Abuelfotoh, Hazem
[-- Attachment #1: Type: text/plain, Size: 2209 bytes --]
On Fri, 2025-02-07 at 08:13 +0100, Mateusz Polchlopek wrote:
>
>
> On 2/6/2025 6:45 PM, Thomas Weißschuh wrote:
> > Some error handling issues I noticed while looking at the code.
> >
> > Only compile-tested.
> >
> > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > ---
> > Thomas Weißschuh (4):
> > ptp: vmclock: Set driver data before its usage
> > ptp: vmclock: Don't unregister misc device if it was not registered
> > ptp: vmclock: Clean up miscdev and ptp clock through devres
> > ptp: vmclock: Remove goto-based cleanup logic
> >
> > drivers/ptp/ptp_vmclock.c | 46 ++++++++++++++++++++--------------------------
> > 1 file changed, 20 insertions(+), 26 deletions(-)
> > ---
> > base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> > change-id: 20250206-vmclock-probe-57cbcb770925
> >
> > Best regards,
>
> As those all are fixes and cleanups then I think it should be tagged to
> net not net-next.
Agreed. Thanks, Thomas. For all four:
Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
I'm about to post a fifth which adds a .owner to vmclock_miscdev_fops.
Tested with the existing '-device vmclock' support in QEMU, plus this
hack to actually expose a PTP clock to the guest (which we haven't
worked out how to do *properly* from the timekeeping subsystem of a
Linux host yet; qv).
--- a/hw/acpi/vmclock.c
+++ b/hw/acpi/vmclock.c
@@ -151,6 +151,18 @@ static void vmclock_realize(DeviceState *dev,
Error **errp)
qemu_register_reset(vmclock_handle_reset, vms);
+ vms->clk->time_type = VMCLOCK_TIME_TAI;
+ vms->clk->flags = VMCLOCK_FLAG_TAI_OFFSET_VALID;
+ vms->clk->tai_offset_sec = -3600;
+ vms->clk->clock_status = VMCLOCK_STATUS_SYNCHRONIZED;
+ vms->clk->counter_value = 0;
+ vms->clk->counter_id = VMCLOCK_COUNTER_X86_TSC;
+ vms->clk->time_sec = 1704067200;
+ vms->clk->time_frac_sec = 0x8000000000000000ULL;
+ vms->clk->counter_period_frac_sec = 0x1a6e39b3e0ULL;
+ vms->clk->counter_period_shift = 4;
+ //vms->clk->counter_period_frac_sec = 0x1934c67f9b2ce6ULL;
+
vmclock_update_guest(vms);
}
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 5/4] ptp: vmclock: Add .owner to vmclock_miscdev_fops
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
` (5 preceding siblings ...)
2025-02-07 7:13 ` Mateusz Polchlopek
@ 2025-02-07 9:13 ` David Woodhouse
6 siblings, 0 replies; 12+ messages in thread
From: David Woodhouse @ 2025-02-07 9:13 UTC (permalink / raw)
To: Thomas Weißschuh, Richard Cochran, Andrew Lunn,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: netdev, linux-kernel, stable, Mateusz Polchlopek,
Mohamed Abuelfotoh, Hazem
[-- Attachment #1: Type: text/plain, Size: 831 bytes --]
From: David Woodhouse <dwmw@amazon.co.uk>
Without the .owner field, the module can be unloaded while /dev/vmclock0
is open, leading to an oops.
Fixes: 205032724226 ("ptp: Add support for the AMZNC10C 'vmclock' device")
Cc: stable@vger.kernel.org
Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
---
drivers/ptp/ptp_vmclock.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/ptp/ptp_vmclock.c b/drivers/ptp/ptp_vmclock.c
index 26fcc1185ee7..b3a83b03d9c1 100644
--- a/drivers/ptp/ptp_vmclock.c
+++ b/drivers/ptp/ptp_vmclock.c
@@ -414,6 +414,7 @@ static ssize_t vmclock_miscdev_read(struct file *fp, char __user *buf,
}
static const struct file_operations vmclock_miscdev_fops = {
+ .owner = THIS_MODULE,
.mmap = vmclock_miscdev_mmap,
.read = vmclock_miscdev_read,
};
--
2.48.1
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling
2025-02-07 9:10 ` David Woodhouse
@ 2025-02-07 9:25 ` Thomas Weißschuh
2025-02-07 9:29 ` David Woodhouse
0 siblings, 1 reply; 12+ messages in thread
From: Thomas Weißschuh @ 2025-02-07 9:25 UTC (permalink / raw)
To: David Woodhouse
Cc: Mateusz Polchlopek, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
stable, Mohamed Abuelfotoh, Hazem
On Fri, Feb 07, 2025 at 09:10:42AM +0000, David Woodhouse wrote:
> On Fri, 2025-02-07 at 08:13 +0100, Mateusz Polchlopek wrote:
> >
> >
> > On 2/6/2025 6:45 PM, Thomas Weißschuh wrote:
> > > Some error handling issues I noticed while looking at the code.
> > >
> > > Only compile-tested.
> > >
> > > Signed-off-by: Thomas Weißschuh <thomas.weissschuh@linutronix.de>
> > > ---
> > > Thomas Weißschuh (4):
> > > ptp: vmclock: Set driver data before its usage
> > > ptp: vmclock: Don't unregister misc device if it was not registered
> > > ptp: vmclock: Clean up miscdev and ptp clock through devres
> > > ptp: vmclock: Remove goto-based cleanup logic
> > >
> > > drivers/ptp/ptp_vmclock.c | 46 ++++++++++++++++++++--------------------------
> > > 1 file changed, 20 insertions(+), 26 deletions(-)
> > > ---
> > > base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
> > > change-id: 20250206-vmclock-probe-57cbcb770925
> > >
> > > Best regards,
> >
> > As those all are fixes and cleanups then I think it should be tagged to
> > net not net-next.
>
> Agreed. Thanks, Thomas. For all four:
Ack.
> Reviewed-by: David Woodhouse <dwmw@amazon.co.uk>
Thanks.
> I'm about to post a fifth which adds a .owner to vmclock_miscdev_fops.
I assume you want me to include this in my series.
> Tested with the existing '-device vmclock' support in QEMU, plus this
> hack to actually expose a PTP clock to the guest (which we haven't
> worked out how to do *properly* from the timekeeping subsystem of a
> Linux host yet; qv).
>
> --- a/hw/acpi/vmclock.c
> +++ b/hw/acpi/vmclock.c
> @@ -151,6 +151,18 @@ static void vmclock_realize(DeviceState *dev,
> Error **errp)
>
> qemu_register_reset(vmclock_handle_reset, vms);
>
> + vms->clk->time_type = VMCLOCK_TIME_TAI;
> + vms->clk->flags = VMCLOCK_FLAG_TAI_OFFSET_VALID;
> + vms->clk->tai_offset_sec = -3600;
> + vms->clk->clock_status = VMCLOCK_STATUS_SYNCHRONIZED;
> + vms->clk->counter_value = 0;
> + vms->clk->counter_id = VMCLOCK_COUNTER_X86_TSC;
> + vms->clk->time_sec = 1704067200;
> + vms->clk->time_frac_sec = 0x8000000000000000ULL;
> + vms->clk->counter_period_frac_sec = 0x1a6e39b3e0ULL;
> + vms->clk->counter_period_shift = 4;
> + //vms->clk->counter_period_frac_sec = 0x1934c67f9b2ce6ULL;
> +
> vmclock_update_guest(vms);
> }
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling
2025-02-07 9:25 ` Thomas Weißschuh
@ 2025-02-07 9:29 ` David Woodhouse
0 siblings, 0 replies; 12+ messages in thread
From: David Woodhouse @ 2025-02-07 9:29 UTC (permalink / raw)
To: Thomas Weißschuh
Cc: Mateusz Polchlopek, Richard Cochran, Andrew Lunn, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, netdev, linux-kernel,
stable, Mohamed Abuelfotoh, Hazem
[-- Attachment #1: Type: text/plain, Size: 346 bytes --]
On Fri, 2025-02-07 at 10:25 +0100, Thomas Weißschuh wrote:
> > I'm about to post a fifth which adds a .owner to vmclock_miscdev_fops.
>
> I assume you want me to include this in my series.
If you do need to repost the series, yes please. Otherwise I've posted
it as [PATCH 5/4] so hopefully it'll get swept up with the original
set.
[-- Attachment #2: smime.p7s --]
[-- Type: application/pkcs7-signature, Size: 5069 bytes --]
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2025-02-07 9:29 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-06 17:45 [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 1/4] ptp: vmclock: Set driver data before its usage Thomas Weißschuh
2025-02-07 7:07 ` Mateusz Polchlopek
2025-02-06 17:45 ` [PATCH net-next 2/4] ptp: vmclock: Don't unregister misc device if it was not registered Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 3/4] ptp: vmclock: Clean up miscdev and ptp clock through devres Thomas Weißschuh
2025-02-06 17:45 ` [PATCH net-next 4/4] ptp: vmclock: Remove goto-based cleanup logic Thomas Weißschuh
2025-02-07 5:43 ` [PATCH net-next 0/4] ptp: vmclock: bugfixes and cleanups for error handling Richard Cochran
2025-02-07 7:13 ` Mateusz Polchlopek
2025-02-07 9:10 ` David Woodhouse
2025-02-07 9:25 ` Thomas Weißschuh
2025-02-07 9:29 ` David Woodhouse
2025-02-07 9:13 ` [PATCH net-next 5/4] ptp: vmclock: Add .owner to vmclock_miscdev_fops David Woodhouse
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).