Skip to contentSkip to conversation

virt: vmgenid: Add devicetree bindings support

PATCH Superseded Sudan Landge 6 participants 17 messages Mar 25, 2024 – Mar 26, 2024

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover virt: vmgenid: Add devicetree bindings support

This small series of patches aims to add devicetree bindings support for the Virtual Machine Generation ID (vmgenid).

Virtual Machine Generation ID was introduced in commit af6b54e2b5ba ("virt: vmgenid: notify RNG of VM fork and supply generation ID") as an ACPI only device.

VMGenID specification http://go.microsoft.com/fwlink/?LinkId=260709 defines a mechanism for the BIOS/hypervisors to communicate to the virtual machine that it is executed with a different configuration (e.g. snapshot execution or creation from a template).
The guest operating system can use the notification for various purposes such as re-initializing its random number generator etc.

More references to vmgenid specs:
- https://www.qemu.org/docs/master/specs/vmgenid.html
- https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/virtual-machine-generation-identifier

*Reason for this change*:
Chosing ACPI or devicetree is an intrinsic part of an hypervisor design. Without going into details of why a hypervisor would chose DT over ACPI, we would like to highlight that the hypervisors that have chose devicetree and now want to make use of the vmgenid functionality cannot do so today because vmgenid is an ACPI only device.
This forces these hypervisors to change their design which could have undesirable impacts on their use-cases, test-scenarios etc.

The point of vmgenid is to provide a mechanism to discover a GUID when the execution state of a virtual machine changes and the simplest way to do it is pass a memory location and an interrupt via devicetree. It would complicate things unnecessarily if instead of using devicetree, we try to implement a new protocol or modify other protocols to somehow provide the same functionility.

We believe that adding a devicetree binding for vmgenid is a simpler, better alternative to provide the same functionality and will allow such hypervisors as mentioned above to continue using devicetree.

Addtional notes:
While adding the devicetree support we considered re-using existing structures/code to avoid duplication code and reduce maintenance; so, we used the same driver to be configured either by ACPI or by DT. This also meant reimplementing the existing vmgenid ACPI bus driver as a platform driver and making it discoverable using driver.of_match_table and driver.acpi_match_table.

There is no user impact or change in vmgenid functionality when used with ACPI. We verified ACPI support of these patches on X86 and DT support on ARM using Firecracker hypervisor
https://github.com/firecracker-microvm/firecracker.

To check schema and syntax errors, the bindings file is verified with:

```
  make dt_binding_check \
  DT_SCHEMA_FILES=Documentation/devicetree/bindings/vmgenid/vmgenid.yaml
```

and the patches were verified with:
scripts/checkpatch.pl --strict v1-000*.

Changelog with respect to version 2:
- As per review comments, used platform apis instead of "of_*" APIs, removed unnecessary #include and used IF_ENABLED instead of ifdef.
- Added more info for vmgenid buffer address and corrected the formatting.
- Replaced the compatible string from "linux,*" to "virtual,*" because, the device does not have a vendor.

Changelog with respect to version 1:
- Moved vmgenid.yaml bindings to the more related "rng" folder.
- Removed vmgenid_remove to since it is unrelated to the current goal of the patch.
- Updated the cover letter and bindings commit "[PATCH v2 3/4] dt-bindings: rng: Add vmgenid support" to provide more information on vmgenid.
- Compiled with and without CONFIG_OF/CONFIG_ACPI and fixed compilers errors/warnings.

Sudan Landge (4):
virt: vmgenid: rearrange code to make review easier
virt: vmgenid: change implementation to use a platform driver
dt-bindings: rng: Add vmgenid support
virt: vmgenid: add support for devicetree bindings

 .../devicetree/bindings/rng/vmgenid.yaml      |  58 ++++++
 MAINTAINERS                                   |   1 +
 drivers/virt/Kconfig                          |   1 -
 drivers/virt/vmgenid.c                        | 194 ++++++++++++++----
 4 files changed, 217 insertions(+), 37 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/rng/vmgenid.yaml

base-commit: 8e938e39866920ddc266898e6ae1fffc5c8f51aa

Signature · 1 line
2.40.1
#1 lore raw

PATCH v3 1/4 virt: vmgenid: rearrange code to make review easier

Rearrage the functions of vmgenid to make the next commit, which re-implements vmgenid as a platform driver, easier to review.

---
 drivers/virt/vmgenid.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/virt/vmgenid.c +14 -14
index b67a28da4702..ea956df02874 100644
@@ -21,6 +21,20 @@ struct vmgenid_state {
 	u8 this_id[VMGENID_SIZE];
 };
 
+static void vmgenid_notify(struct acpi_device *device, u32 event)
+{
+	struct vmgenid_state *state = acpi_driver_data(device);
+	char *envp[] = { "NEW_VMGENID=1", NULL };
+	u8 old_id[VMGENID_SIZE];
+
+	memcpy(old_id, state->this_id, sizeof(old_id));
+	memcpy(state->this_id, state->next_id, sizeof(state->this_id));
+	if (!memcmp(old_id, state->this_id, sizeof(old_id)))
+		return;
+	add_vmfork_randomness(state->this_id, sizeof(state->this_id));
+	kobject_uevent_env(&device->dev.kobj, KOBJ_CHANGE, envp);
+}
+
 static int vmgenid_add(struct acpi_device *device)
 {
 	struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
@@ -65,20 +79,6 @@ static int vmgenid_add(struct acpi_device *device)
 	return ret;
 }
 
-static void vmgenid_notify(struct acpi_device *device, u32 event)
-{
-	struct vmgenid_state *state = acpi_driver_data(device);
-	char *envp[] = { "NEW_VMGENID=1", NULL };
-	u8 old_id[VMGENID_SIZE];
-
-	memcpy(old_id, state->this_id, sizeof(old_id));
-	memcpy(state->this_id, state->next_id, sizeof(state->this_id));
-	if (!memcmp(old_id, state->this_id, sizeof(old_id)))
-		return;
-	add_vmfork_randomness(state->this_id, sizeof(state->this_id));
-	kobject_uevent_env(&device->dev.kobj, KOBJ_CHANGE, envp);
-}
-
 static const struct acpi_device_id vmgenid_ids[] = {
 	{ "VMGENCTR", 0 },
 	{ "VM_GEN_COUNTER", 0 },
Signature · 1 line
2.40.1
#2 lore raw

PATCH v3 2/4 virt: vmgenid: change implementation to use a platform driver

In reply to Sudan Landge

Re-implement vmgenid as a platform driver in preparation for adding devicetree bindings support in next commits.

---
 drivers/virt/vmgenid.c | 101 ++++++++++++++++++++++++++++++-----------
 1 file changed, 74 insertions(+), 27 deletions(-)
drivers/virt/vmgenid.c +74 -27
index ea956df02874..d5394c706bd9 100644
@@ -11,6 +11,8 @@
 #include <linux/module.h>
 #include <linux/acpi.h>
 #include <linux/random.h>
+#include <acpi/actypes.h>
+#include <linux/platform_device.h>
 
 ACPI_MODULE_NAME("vmgenid");
 
@@ -21,9 +23,9 @@ struct vmgenid_state {
 	u8 this_id[VMGENID_SIZE];
 };
 
-static void vmgenid_notify(struct acpi_device *device, u32 event)
+static void vmgenid_notify(struct device *device)
 {
-	struct vmgenid_state *state = acpi_driver_data(device);
+	struct vmgenid_state *state = device->driver_data;
 	char *envp[] = { "NEW_VMGENID=1", NULL };
 	u8 old_id[VMGENID_SIZE];
 
@@ -32,22 +34,34 @@ static void vmgenid_notify(struct acpi_device *device, u32 event)
 	if (!memcmp(old_id, state->this_id, sizeof(old_id)))
 		return;
 	add_vmfork_randomness(state->this_id, sizeof(state->this_id));
-	kobject_uevent_env(&device->dev.kobj, KOBJ_CHANGE, envp);
+	kobject_uevent_env(&device->kobj, KOBJ_CHANGE, envp);
 }
 
-static int vmgenid_add(struct acpi_device *device)
+static void vmgenid_acpi_handler(acpi_handle handle, u32 event, void *dev)
 {
+	vmgenid_notify(dev);
+}
+
+static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
+{
+	if (IS_ERR(next_id))
+		return PTR_ERR(next_id);
+
+	state->next_id = next_id;
+	memcpy(state->this_id, state->next_id, sizeof(state->this_id));
+	add_device_randomness(state->this_id, sizeof(state->this_id));
+	return 0;
+}
+
+static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
+{
+	struct acpi_device *device = ACPI_COMPANION(dev);
 	struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
-	struct vmgenid_state *state;
 	union acpi_object *obj;
 	phys_addr_t phys_addr;
 	acpi_status status;
 	int ret = 0;
 
-	state = devm_kmalloc(&device->dev, sizeof(*state), GFP_KERNEL);
-	if (!state)
-		return -ENOMEM;
-
 	status = acpi_evaluate_object(device->handle, "ADDR", NULL, &parsed);
 	if (ACPI_FAILURE(status)) {
 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating ADDR"));
@@ -63,19 +77,42 @@ static int vmgenid_add(struct acpi_device *device)
 
 	phys_addr = (obj->package.elements[0].integer.value << 0) |
 		    (obj->package.elements[1].integer.value << 32);
-	state->next_id = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, MEMREMAP_WB);
-	if (IS_ERR(state->next_id)) {
-		ret = PTR_ERR(state->next_id);
+
+	ret = setup_vmgenid_state(state,
+				  (u8 *)devm_memremap(&device->dev, phys_addr,
+						      VMGENID_SIZE, MEMREMAP_WB));
+	if (ret)
+		goto out;
+
+	dev->driver_data = state;
+	status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
+					     vmgenid_acpi_handler, dev);
+	if (ACPI_FAILURE(status)) {
+		dev_err(dev, "Failed to install acpi notify handler");
+		ret = -ENODEV;
+		dev->driver_data = NULL;
 		goto out;
 	}
+out:
+	ACPI_FREE(parsed.pointer);
+	return ret;
+}
 
-	memcpy(state->this_id, state->next_id, sizeof(state->this_id));
-	add_device_randomness(state->this_id, sizeof(state->this_id));
+static int vmgenid_add(struct platform_device *pdev)
+{
+	struct vmgenid_state *state;
+	struct device *dev = &pdev->dev;
+	int ret = 0;
 
-	device->driver_data = state;
+	state = devm_kmalloc(dev, sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return -ENOMEM;
+
+	ret = vmgenid_add_acpi(dev, state);
+
+	if (ret)
+		devm_kfree(dev, state);
 
-out:
-	ACPI_FREE(parsed.pointer);
 	return ret;
 }
 
@@ -84,20 +121,30 @@ static const struct acpi_device_id vmgenid_ids[] = {
 	{ "VM_GEN_COUNTER", 0 },
 	{ }
 };
+MODULE_DEVICE_TABLE(acpi, vmgenid_ids);
 
-static struct acpi_driver vmgenid_driver = {
-	.name = "vmgenid",
-	.ids = vmgenid_ids,
-	.owner = THIS_MODULE,
-	.ops = {
-		.add = vmgenid_add,
-		.notify = vmgenid_notify
-	}
+static struct platform_driver vmgenid_plaform_driver = {
+	.probe      = vmgenid_add,
+	.driver     = {
+		.name   = "vmgenid",
+		.acpi_match_table = ACPI_PTR(vmgenid_ids),
+		.owner = THIS_MODULE,
+	},
 };
 
-module_acpi_driver(vmgenid_driver);
+static int vmgenid_platform_device_init(void)
+{
+	return platform_driver_register(&vmgenid_plaform_driver);
+}
+
+static void vmgenid_platform_device_exit(void)
+{
+	platform_driver_unregister(&vmgenid_plaform_driver);
+}
+
+module_init(vmgenid_platform_device_init)
+module_exit(vmgenid_platform_device_exit)
 
-MODULE_DEVICE_TABLE(acpi, vmgenid_ids);
 MODULE_DESCRIPTION("Virtual Machine Generation ID");
 MODULE_LICENSE("GPL v2");
 MODULE_AUTHOR("Jason A. Donenfeld <[email protected]>");
Signature · 1 line
2.40.1
#3 lore raw

Re: [PATCH v3 2/4] virt: vmgenid: change implementation to use a platform driver

Quoted 13 lines · Sudan Landge

Re-implement vmgenid as a platform driver in preparation for adding devicetree bindings support in next commits.

---
 drivers/virt/vmgenid.c | 101 ++++++++++++++++++++++++++++++-----------
 1 file changed, 74 insertions(+), 27 deletions(-)
drivers/virt/vmgenid.c +0 -0
index ea956df02874..d5394c706bd9 100644

drivers/virt/vmgenid.c line 15

Quoted 5 lines
drivers/virt/vmgenid.c +2 -0
@@ -11,6 +11,8 @@
 #include <linux/module.h>
 #include <linux/acpi.h>
 #include <linux/random.h>
+#include <acpi/actypes.h>
+#include <linux/platform_device.h>

Do not add headers to the end of lists.

Quoted 3 lines
drivers/virt/vmgenid.c +0 -0
 ACPI_MODULE_NAME("vmgenid");
 

...

Quoted 4 lines
drivers/virt/vmgenid.c +0 -3
-static struct acpi_driver vmgenid_driver = {
-	.name = "vmgenid",
-	.ids = vmgenid_ids,

drivers/virt/vmgenid.c static const struct acpi_device_id vmgenid_ids[] = { · line 130

Quoted 10 lines
drivers/virt/vmgenid.c +5 -5
-	.owner = THIS_MODULE,
-	.ops = {
-		.add = vmgenid_add,
-		.notify = vmgenid_notify
-	}
+static struct platform_driver vmgenid_plaform_driver = {
+	.probe      = vmgenid_add,
+	.driver     = {
+		.name   = "vmgenid",
+		.acpi_match_table = ACPI_PTR(vmgenid_ids),

ACPI_PTR does not make sense. If this can be compile tested !ACPI, then this is wrong. If this cannot be compile tested, then this is redundant and confusing so... also wrong.

Quoted 7 lines
drivers/virt/vmgenid.c +4 -1
+		.owner = THIS_MODULE,
+	},
 };
 
-module_acpi_driver(vmgenid_driver);
+static int vmgenid_platform_device_init(void)
+{

drivers/virt/vmgenid.c static const struct acpi_device_id vmgenid_ids[] = { · line 146

Quoted 10 lines
drivers/virt/vmgenid.c +10 -0
+	return platform_driver_register(&vmgenid_plaform_driver);
+}
+
+static void vmgenid_platform_device_exit(void)
+{
+	platform_driver_unregister(&vmgenid_plaform_driver);
+}
+
+module_init(vmgenid_platform_device_init)
+module_exit(vmgenid_platform_device_exit)

Why this cannot be module_platform_driver?

Best regards,
Krzysztof

#4 lore raw

PATCH v3 3/4 dt-bindings: rng: Add vmgenid support

In reply to Sudan Landge

Virtual Machine Generation ID driver was introduced in commit af6b54e2b5ba ("virt: vmgenid: notify RNG of VM fork and supply generation ID"), as an ACPI only device.

VMGenID specification http://go.microsoft.com/fwlink/?LinkId=260709 defines a mechanism for the BIOS/hypervisors to communicate to the virtual machine that it is executed with a different configuration (e.g. snapshot execution or creation from a template).
The guest operating system can use the notification for various purposes such as re-initializing its random number generator etc.

As per the specs, hypervisor should provide a globally unique identified, or GUID via ACPI.

This patch tries to mimic the mechanism to provide the same functionality which is for a hypervisor/BIOS to notify the virtual machine when it is executed with a different configuration.

As part of this support the devicetree bindings requires the hypervisors or BIOS to provide a memory address which holds the GUID and an IRQ which is used to notify when there is a change in the GUID.
The memory exposed in the DT should follow the rules defined in the vmgenid spec mentioned above.

*Reason for this change*:
Chosing ACPI or devicetree is an intrinsic part of an hypervisor design. Without going into details of why a hypervisor would chose DT over ACPI, we would like to highlight that the hypervisors that have chose devicetree and now want to make use of the vmgenid functionality cannot do so today because vmgenid is an ACPI only device.
This forces these hypervisors to change their design which could have undesirable impacts on their use-cases, test-scenarios etc.

The point of vmgenid is to provide a mechanism to discover a GUID when the execution state of a virtual machine changes and the simplest way to do it is pass a memory location and an interrupt via devicetree. It would complicate things unnecessarily if instead of using devicetree, we try to implement a new protocol or modify other protocols to somehow provide the same functionility.

We believe that adding a devicetree binding for vmgenid is a simpler, better alternative to provide the same functionality and will allow such hypervisors as mentioned above to continue using devicetree.

More references to vmgenid specs:
- https://www.qemu.org/docs/master/specs/vmgenid.html
- https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/virtual-
machine-generation-identifier

---
 .../devicetree/bindings/rng/vmgenid.yaml      | 58 +++++++++++++++++++
 MAINTAINERS                                   |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rng/vmgenid.yaml
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +58 -0
new file mode 100644
index 000000000000..24643080d6b0
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/vmgenid.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Virtual Machine Generation Counter ID device
+
+maintainers:
+  - Jason A. Donenfeld <[email protected]>
+
+description:
+  Firmwares or hypervisors can use this devicetree to describe
+  interrupts and the shared resources to inject a Virtual Machine Generation
+  counter.
+
+properties:
+  compatible:
+    const: virtual,vmgenctr
+
+  "#interrupt-cells":
+    const: 3
+    description:
+      The 1st cell is the interrupt type.
+      The 2nd cell contains the interrupt number for the interrupt type.
+      The 3rd cell is for trigger type and level flags.
+
+  interrupt-map: true
+
+  reg:
+    description:
+      The 1st cell specifies the base physical address of the 8-byte aligned
+      buffer in guest memory space which is guaranteed not to be used by the
+      operating system.
+      The 2nd cell specifies the size of the buffer which holds the VMGenID.
+    maxItems: 1
+
+  interrupts:
+    description:
+      interrupt used to notify that a new VMGenID counter is available.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    rng@80000000 {
+      compatible = "virtual,vmgenctr";
+      reg = <0x80000000 0x1000>;
+      interrupts = <0x00 0x23 0x01>;
+    };
+
+...
MAINTAINERS +1 -0
index de6a64b248ae..e295d2f50af4 100644
@@ -18461,6 +18461,7 @@ M:	"Theodore Ts'o" <[email protected]>
 M:	Jason A. Donenfeld <[email protected]>
 S:	Maintained
 T:	git https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git
+F:	Documentation/devicetree/bindings/rng/vmgenid.yaml
 F:	drivers/char/random.c
 F:	drivers/virt/vmgenid.c
 
Signature · 1 line
2.40.1
#5 lore raw

Re: [PATCH v3 3/4] dt-bindings: rng: Add vmgenid support

Quoted 1 line · Sudan Landge

Please give time for discussions on prior versions to finish and others to comment. We're not all in one timezone and are busy. I've replied there too.

Quoted 44 lines

Virtual Machine Generation ID driver was introduced in commit af6b54e2b5ba ("virt: vmgenid: notify RNG of VM fork and supply generation ID"), as an ACPI only device.

VMGenID specification http://go.microsoft.com/fwlink/?LinkId=260709 defines a mechanism for the BIOS/hypervisors to communicate to the virtual machine that it is executed with a different configuration (e.g. snapshot execution or creation from a template).
The guest operating system can use the notification for various purposes such as re-initializing its random number generator etc.

As per the specs, hypervisor should provide a globally unique identified, or GUID via ACPI.

This patch tries to mimic the mechanism to provide the same functionality which is for a hypervisor/BIOS to notify the virtual machine when it is executed with a different configuration.

As part of this support the devicetree bindings requires the hypervisors or BIOS to provide a memory address which holds the GUID and an IRQ which is used to notify when there is a change in the GUID.
The memory exposed in the DT should follow the rules defined in the vmgenid spec mentioned above.

*Reason for this change*:
Chosing ACPI or devicetree is an intrinsic part of an hypervisor design. Without going into details of why a hypervisor would chose DT over ACPI, we would like to highlight that the hypervisors that have chose devicetree and now want to make use of the vmgenid functionality cannot do so today because vmgenid is an ACPI only device.
This forces these hypervisors to change their design which could have undesirable impacts on their use-cases, test-scenarios etc.

The point of vmgenid is to provide a mechanism to discover a GUID when the execution state of a virtual machine changes and the simplest way to do it is pass a memory location and an interrupt via devicetree. It would complicate things unnecessarily if instead of using devicetree, we try to implement a new protocol or modify other protocols to somehow provide the same functionility.

We believe that adding a devicetree binding for vmgenid is a simpler, better alternative to provide the same functionality and will allow such hypervisors as mentioned above to continue using devicetree.

Quoted 8 lines

More references to vmgenid specs:
- https://www.qemu.org/docs/master/specs/vmgenid.html
- https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/virtual-
machine-generation-identifier

---
 .../devicetree/bindings/rng/vmgenid.yaml      | 58 +++++++++++++++++++

Filename should match the compatible, whatever that ends up being.

Quoted 29 lines
 MAINTAINERS                                   |  1 +
 2 files changed, 59 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/rng/vmgenid.yaml
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +19 -0
new file mode 100644
index 000000000000..24643080d6b0
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/vmgenid.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Virtual Machine Generation Counter ID device
+
+maintainers:
+  - Jason A. Donenfeld <[email protected]>
+
+description:
+  Firmwares or hypervisors can use this devicetree to describe
+  interrupts and the shared resources to inject a Virtual Machine Generation
+  counter.
+
+properties:
+  compatible:
+    const: virtual,vmgenctr

Documentation/devicetree/bindings/rng/vmgenid.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +10 -0
+
+
+  "#interrupt-cells":
+    const: 3
+    description:
+      The 1st cell is the interrupt type.
+      The 2nd cell contains the interrupt number for the interrupt type.
+      The 3rd cell is for trigger type and level flags.
+
+  interrupt-map: true

Sigh. What makes this an interrupt-map? Why do you think you need this and #interrupt-cells? You don't have them in the example.

Documentation/devicetree/bindings/rng/vmgenid.yaml line 35

Quoted 7 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +7 -0
+
+  reg:
+    description:
+      The 1st cell specifies the base physical address of the 8-byte aligned
+      buffer in guest memory space which is guaranteed not to be used by the
+      operating system.
+      The 2nd cell specifies the size of the buffer which holds the VMGenID.

I didn't ask for you to explain the purpose of cells in 'reg' as that is the same for *every* instance of 'reg'. Ignore DTisms and describe the format of the registers. For example, is it 4 32-bit registers (hex) or 9 32-bit registers (ascii)?

Quoted 39 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +23 -0
+    maxItems: 1
+
+  interrupts:
+    description:
+      interrupt used to notify that a new VMGenID counter is available.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    rng@80000000 {
+      compatible = "virtual,vmgenctr";
+      reg = <0x80000000 0x1000>;
+      interrupts = <0x00 0x23 0x01>;
+    };
+
+...
MAINTAINERS +1 -1
index de6a64b248ae..e295d2f50af4 100644
@@ -18461,6 +18461,7 @@ M:      "Theodore Ts'o" <[email protected]>
 M:     Jason A. Donenfeld <[email protected]>
 S:     Maintained
 T:     git https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git
+F:     Documentation/devicetree/bindings/rng/vmgenid.yaml
 F:     drivers/char/random.c
 F:     drivers/virt/vmgenid.c
 
--

2.40.1

#6 lore raw

Re: [PATCH v3 3/4] dt-bindings: rng: Add vmgenid support

In reply to Sudan Landge
Quoted 3 lines · Sudan Landge

Virtual Machine Generation ID driver was introduced in commit af6b54e2b5ba ("virt: vmgenid: notify RNG of VM fork and supply generation ID"), as an ACPI only device.

...

Quoted 22 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +16 -0
new file mode 100644
index 000000000000..24643080d6b0
@@ -0,0 +1,58 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/rng/vmgenid.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Virtual Machine Generation Counter ID device
+
+maintainers:
+  - Jason A. Donenfeld <[email protected]>
+
+description:
+  Firmwares or hypervisors can use this devicetree to describe
+  interrupts and the shared resources to inject a Virtual Machine Generation
+  counter.
+

Documentation/devicetree/bindings/rng/vmgenid.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +10 -0
+properties:
+  compatible:
+    const: virtual,vmgenctr
+
+  "#interrupt-cells":
+    const: 3
+    description:
+      The 1st cell is the interrupt type.
+      The 2nd cell contains the interrupt number for the interrupt type.
+      The 3rd cell is for trigger type and level flags.

How is this interrupt-controller now? You already got such comment on v2.

Quoted 19 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +19 -0
+
+  interrupt-map: true
+
+  reg:
+    description:
+      The 1st cell specifies the base physical address of the 8-byte aligned
+      buffer in guest memory space which is guaranteed not to be used by the
+      operating system.
+      The 2nd cell specifies the size of the buffer which holds the VMGenID.
+    maxItems: 1
+
+  interrupts:
+    description:
+      interrupt used to notify that a new VMGenID counter is available.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg

Documentation/devicetree/bindings/rng/vmgenid.yaml line 55

Quoted 10 lines
Documentation/devicetree/bindings/rng/vmgenid.yaml new file +10 -0
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    rng@80000000 {
+      compatible = "virtual,vmgenctr";
+      reg = <0x80000000 0x1000>;
+      interrupts = <0x00 0x23 0x01>;

Use standard defines and drop padding from hex numbers. Or just use decimal numbers because hex is anyway unusual, unless this is what your device datasheet says.

And what is 0x00 in the interrupt?

Best regards,
Krzysztof

#7 lore raw

PATCH v3 4/4 virt: vmgenid: add support for devicetree bindings

In reply to Sudan Landge

- Extend the vmgenid platform driver to support devicetree bindings. With this support, hypervisors can send vmgenid notifications to the virtual machine without the need to enable ACPI. The bindings are located at: Documentation/devicetree/bindings/rng/vmgenid.yaml

- Use proper FLAGS to compile with and without ACPI and/or devicetree.

---
 drivers/virt/Kconfig   |  1 -
 drivers/virt/vmgenid.c | 85 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 80 insertions(+), 6 deletions(-)
drivers/virt/Kconfig +0 -1
index 40129b6f0eca..d8c848cf09a6 100644
@@ -16,7 +16,6 @@ if VIRT_DRIVERS
 config VMGENID
 	tristate "Virtual Machine Generation ID driver"
 	default y
-	depends on ACPI
 	help
 	  Say Y here to use the hypervisor-provided Virtual Machine Generation ID
 	  to reseed the RNG when the VM is cloned. This is highly recommended if
drivers/virt/vmgenid.c +80 -5

140 lines not on this page · raw message

Signature · 1 line
2.40.1
#8 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

Quoted 6 lines · Sudan Landge

- Extend the vmgenid platform driver to support devicetree bindings. With this support, hypervisors can send vmgenid notifications to the virtual machine without the need to enable ACPI. The bindings are located at: Documentation/devicetree/bindings/rng/vmgenid.yaml

- Use proper FLAGS to compile with and without ACPI and/or devicetree.

I do not see any flags. You use if/ifdefs which is a NAK.

Do not mix independent changes within one commit. Please follow guidelines in submitting-patches for this.

Quoted 7 lines
---
 drivers/virt/Kconfig   |  1 -
 drivers/virt/vmgenid.c | 85 +++++++++++++++++++++++++++++++++++++++---
 2 files changed, 80 insertions(+), 6 deletions(-)

...

Quoted 14 lines
drivers/virt/vmgenid.c +10 -0
+
+#if IS_ENABLED(CONFIG_OF)
+static irqreturn_t vmgenid_of_irq_handler(int irq, void *dev)
+{
+	(void)irq;
+	vmgenid_notify(dev);
+
+	return IRQ_HANDLED;
+}
+#endif
 
 static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
 {

drivers/virt/vmgenid.c static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) · line 73

Quoted 4 lines
drivers/virt/vmgenid.c +1 -0
@@ -55,6 +70,7 @@ static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
 
 static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
 {
+#if IS_ENABLED(CONFIG_ACPI)

Why do you create all this ifdeffery in the code? You already got comments to get rid of all this #if.

Quoted 36 lines
drivers/virt/vmgenid.c +29 -0
 	struct acpi_device *device = ACPI_COMPANION(dev);
 	struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
 	union acpi_object *obj;
@@ -96,6 +112,49 @@ static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
 out:
 	ACPI_FREE(parsed.pointer);
 	return ret;
+#else
+	(void)dev;
+	(void)state;
+	return -EINVAL;
+#endif
+}
+
+static int vmgenid_add_of(struct platform_device *pdev, struct vmgenid_state *state)
+{
+#if IS_ENABLED(CONFIG_OF)
+	void __iomem *remapped_ptr;
+	int ret = 0;
+
+	remapped_ptr = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
+	if (IS_ERR(remapped_ptr)) {
+		ret = PTR_ERR(remapped_ptr);
+		goto out;
+	}
+
+	ret = setup_vmgenid_state(state, remapped_ptr);
+	if (ret)
+		goto out;
+
+	state->irq = platform_get_irq(pdev, 0);
+	if (state->irq < 0) {
+		ret = state->irq;
+		goto out;
+	}
+	pdev->dev.driver_data = state;

drivers/virt/vmgenid.c static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state) · line 153

Quoted 10 lines
drivers/virt/vmgenid.c +10 -0
+
+	ret =  devm_request_irq(&pdev->dev, state->irq,
+				vmgenid_of_irq_handler,
+				IRQF_SHARED, "vmgenid", &pdev->dev);
+	if (ret)
+		pdev->dev.driver_data = NULL;
+
+out:
+	return ret;
+#else

That's neither readable code nor matching Linux coding style. Driver don't do such magic. Please open some recent drivers for ACPI and OF and look there. Old drivers had stubs for !CONFIG_XXX, but new drivers don't have even that.

Quoted 20 lines
drivers/virt/vmgenid.c +8 -1
+	(void)dev;
+	(void)state;
+	return -EINVAL;
+#endif
 }
 
 static int vmgenid_add(struct platform_device *pdev)
@@ -108,7 +167,10 @@ static int vmgenid_add(struct platform_device *pdev)
 	if (!state)
 		return -ENOMEM;
 
-	ret = vmgenid_add_acpi(dev, state);
+	if (dev->of_node)
+		ret = vmgenid_add_of(pdev, state);
+	else
+		ret = vmgenid_add_acpi(dev, state);
 
 	if (ret)
 		devm_kfree(dev, state);

drivers/virt/vmgenid.c static int vmgenid_add(struct platform_device *pdev) · line 181

Quoted 5 lines
drivers/virt/vmgenid.c +1 -1
@@ -116,18 +178,31 @@ static int vmgenid_add(struct platform_device *pdev)
 	return ret;
 }
 
-static const struct acpi_device_id vmgenid_ids[] = {
+#if IS_ENABLED(CONFIG_OF)

No, drop.

Quoted 16 lines
(quoted diff) +9 -1
+static const struct of_device_id vmgenid_of_ids[] = {
+	{ .compatible = "linux,vmgenctr", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, vmgenid_of_ids);
+#endif
+
+#if IS_ENABLED(CONFIG_ACPI)
 
 
+static const struct acpi_device_id vmgenid_acpi_ids[] = {
 	{ "VMGENCTR", 0 },
 	{ "VM_GEN_COUNTER", 0 },
 	{ }
 };
-MODULE_DEVICE_TABLE(acpi, vmgenid_ids);

Review static int vmgenid_add(struct platform_device *pdev) · line 205

Quoted 10 lines
(quoted diff) +4 -1
+MODULE_DEVICE_TABLE(acpi, vmgenid_acpi_ids);
+#endif
 
 static struct platform_driver vmgenid_plaform_driver = {
 	.probe      = vmgenid_add,
 	.driver     = {
 		.name   = "vmgenid",
-		.acpi_match_table = ACPI_PTR(vmgenid_ids),
+		.acpi_match_table = ACPI_PTR(vmgenid_acpi_ids),
+#if IS_ENABLED(CONFIG_OF)

No, really, this is some ancient code.

Please point me to single driver doing such ifdef.

drivers/virt/vmgenid.c static int vmgenid_add(struct platform_device *pdev) · line 206

Quoted 3 lines
drivers/virt/vmgenid.c +2 -0
+		.of_match_table = vmgenid_of_ids,
+#endif
 		.owner = THIS_MODULE,

This is clearly some abandoned driver... sigh... I thought we get rid of all this owner crap. Many years ago. How could it appear back if automated tools report it?

Considering how many failures LKP reported for your patchsets, I have real doubts that anyone actually tests this code.

Please confirm:
Did you build W=1, run smatch, sparse and coccinelle on the driver after your changes?

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

Quoted 10 lines · Krzysztof Kozlowski

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 5 lines · Sudan Landge

- Extend the vmgenid platform driver to support devicetree bindings. With this support, hypervisors can send vmgenid notifications to the virtual machine without the need to enable ACPI. The bindings are located at: Documentation/devicetree/bindings/rng/vmgenid.yaml

Quoted 7 lines
Quoted 1 line

- Use proper FLAGS to compile with and without ACPI and/or devicetree.

I do not see any flags. You use if/ifdefs which is a NAK.

Do not mix independent changes within one commit. Please follow guidelines in submitting-patches for this.

By flags, I was referring to "#if IS_ENABLED(CONFIG_ACPI)". I will remove the comment if its incorrect.

Quoted 25 lines
Quoted 7 lines
---
  drivers/virt/Kconfig   |  1 -
  drivers/virt/vmgenid.c | 85 +++++++++++++++++++++++++++++++++++++++---
  2 files changed, 80 insertions(+), 6 deletions(-)

...

Quoted 15 lines
drivers/virt/vmgenid.c +10 -0
+
+#if IS_ENABLED(CONFIG_OF)
+static irqreturn_t vmgenid_of_irq_handler(int irq, void *dev)
+{
+     (void)irq;
+     vmgenid_notify(dev);
+
+     return IRQ_HANDLED;
+}
+#endif
 
  static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
  {
@@ -55,6 +70,7 @@ static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
 
Quoted 7 lines

drivers/virt/vmgenid.c static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id) · line 73

Quoted 3 lines
drivers/virt/vmgenid.c +1 -0
  static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
  {
+#if IS_ENABLED(CONFIG_ACPI)

Why do you create all this ifdeffery in the code? You already got comments to get rid of all this #if.

This was added to avoid errors if CONFIG_ACPI or CONFIG_OF was not enabled. I will refer to other drivers again to see how they handle this.

Quoted 44 lines
Quoted 44 lines
drivers/virt/vmgenid.c +37 -0
       struct acpi_device *device = ACPI_COMPANION(dev);
       struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
       union acpi_object *obj;
@@ -96,6 +112,49 @@ static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
  out:
       ACPI_FREE(parsed.pointer);
       return ret;
+#else
+     (void)dev;
+     (void)state;
+     return -EINVAL;
+#endif
+}
+
+static int vmgenid_add_of(struct platform_device *pdev, struct vmgenid_state *state)
+{
+#if IS_ENABLED(CONFIG_OF)
+     void __iomem *remapped_ptr;
+     int ret = 0;
+
+     remapped_ptr = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
+     if (IS_ERR(remapped_ptr)) {
+             ret = PTR_ERR(remapped_ptr);
+             goto out;
+     }
+
+     ret = setup_vmgenid_state(state, remapped_ptr);
+     if (ret)
+             goto out;
+
+     state->irq = platform_get_irq(pdev, 0);
+     if (state->irq < 0) {
+             ret = state->irq;
+             goto out;
+     }
+     pdev->dev.driver_data = state;
+
+     ret =  devm_request_irq(&pdev->dev, state->irq,
+                             vmgenid_of_irq_handler,
+                             IRQF_SHARED, "vmgenid", &pdev->dev);
+     if (ret)
+             pdev->dev.driver_data = NULL;
+
+out:
Quoted 9 lines

drivers/virt/vmgenid.c static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state) · line 153

Quoted 2 lines
drivers/virt/vmgenid.c +2 -0
+     return ret;
+#else

That's neither readable code nor matching Linux coding style. Driver don't do such magic. Please open some recent drivers for ACPI and OF and look there. Old drivers had stubs for !CONFIG_XXX, but new drivers don't have even that.

Sorry about that, I will refer to a new driver and correct this.

Quoted 70 lines
Quoted 20 lines
drivers/virt/vmgenid.c +8 -1
+     (void)dev;
+     (void)state;
+     return -EINVAL;
+#endif
  }
 
  static int vmgenid_add(struct platform_device *pdev)
@@ -108,7 +167,10 @@ static int vmgenid_add(struct platform_device *pdev)
       if (!state)
               return -ENOMEM;
 
-     ret = vmgenid_add_acpi(dev, state);
+     if (dev->of_node)
+             ret = vmgenid_add_of(pdev, state);
+     else
+             ret = vmgenid_add_acpi(dev, state);
 
       if (ret)
               devm_kfree(dev, state);

drivers/virt/vmgenid.c static int vmgenid_add(struct platform_device *pdev) · line 181

Quoted 5 lines
drivers/virt/vmgenid.c +1 -1
@@ -116,18 +178,31 @@ static int vmgenid_add(struct platform_device *pdev)
       return ret;
  }
 
-static const struct acpi_device_id vmgenid_ids[] = {
+#if IS_ENABLED(CONFIG_OF)

No, drop.

Quoted 16 lines
(quoted diff) +9 -1
+static const struct of_device_id vmgenid_of_ids[] = {
+     { .compatible = "linux,vmgenctr", },
+     {},
+};
+MODULE_DEVICE_TABLE(of, vmgenid_of_ids);
+#endif
+
+#if IS_ENABLED(CONFIG_ACPI)
 
 
+static const struct acpi_device_id vmgenid_acpi_ids[] = {
       { "VMGENCTR", 0 },
       { "VM_GEN_COUNTER", 0 },
       { }
  };
-MODULE_DEVICE_TABLE(acpi, vmgenid_ids);

Review static int vmgenid_add(struct platform_device *pdev) · line 205

Quoted 10 lines
(quoted diff) +4 -1
+MODULE_DEVICE_TABLE(acpi, vmgenid_acpi_ids);
+#endif
 
  static struct platform_driver vmgenid_plaform_driver = {
       .probe      = vmgenid_add,
       .driver     = {
               .name   = "vmgenid",
-             .acpi_match_table = ACPI_PTR(vmgenid_ids),
+             .acpi_match_table = ACPI_PTR(vmgenid_acpi_ids),
+#if IS_ENABLED(CONFIG_OF)

No, really, this is some ancient code.

Please point me to single driver doing such ifdef.

drivers/virt/vmgenid.c static int vmgenid_add(struct platform_device *pdev) · line 206

Quoted 3 lines
drivers/virt/vmgenid.c +2 -0
+             .of_match_table = vmgenid_of_ids,
+#endif
               .owner = THIS_MODULE,

This is clearly some abandoned driver... sigh... I thought we get rid of all this owner crap. Many years ago. How could it appear back if automated tools report it?

Considering how many failures LKP reported for your patchsets, I have real doubts that anyone actually tests this code.

Quoted 7 lines

Please confirm:
Did you build W=1, run smatch, sparse and coccinelle on the driver after your changes?

Best regards,
Krzysztof

I built with W=1 but wasn't aware of the other tools. I will make sure to run all the above before submitting any future patches.

#10 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

In reply to Krzysztof Kozlowski
Quoted 8 lines · Krzysztof Kozlowski
Quoted 1 line

.owner = THIS_MODULE,

This is clearly some abandoned driver... sigh... I thought we get rid of all this owner crap. Many years ago. How could it appear back if automated tools report it?

Considering how many failures LKP reported for your patchsets, I have real doubts that anyone actually tests this code.

Now you're commenting on the context rather than the patch.

No, this isn't an abandoned driver, no it's not untested. Rather, it's code I maintain, care deeply about, and have a tree that receives quite a bit of testing (random.git) where I'll be taking these OF patches in the case that this patchset improves (and thanks very much for your review on it; I'll be appreciative of your ack whenever/if ever it improves to that point), and if you have other cleanups like removing .owner, please don't hesitate to send a patch.

That all is to say, I'm following these threads closely and care.

Jason

#11 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

Quoted 10 lines · Jason A. Donenfeld
Quoted 8 lines · Krzysztof Kozlowski
Quoted 1 line

.owner = THIS_MODULE,

This is clearly some abandoned driver... sigh... I thought we get rid of all this owner crap. Many years ago. How could it appear back if automated tools report it?

Considering how many failures LKP reported for your patchsets, I have real doubts that anyone actually tests this code.

Quoted 6 lines

Now you're commenting on the context rather than the patch.

No, this isn't an abandoned driver, no it's not untested. Rather, it's code I maintain, care deeply about, and have a tree that receives quite a bit of testing (random.git) where I'll be taking these OF patches in the case that this patchset improves (and thanks very much for your

I apologize. I jumped too fast to conclusions and missed important point
- acpi drivers do need to set the owner. I am sorry.

(platform driver do not need, but that's a different thing)

Best regards,
Krzysztof

#12 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

In reply to Sudan Landge
kernel test robot noticed the following build errors:

Hi Sudan,

kernel test robot noticed the following build errors:

[auto build test ERROR on 8e938e39866920ddc266898e6ae1fffc5c8f51aa]

url:    https://github.com/intel-lab-lkp/linux/commits/Sudan-Landge/virt-vmgenid-rearrange-code-to-make-review-easier/20240326-035657
base:   8e938e39866920ddc266898e6ae1fffc5c8f51aa
patch link:    https://lore.kernel.org/r/20240325195306.13133-5-sudanl%40amazon.com
patch subject: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings
config: x86_64-rhel-8.3-bpf (https://download.01.org/0day-ci/archive/20240326/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240326/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

drivers/virt/vmgenid.c: In function 'vmgenid_add_of':

>> drivers/virt/vmgenid.c:154:15: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?
     154 |         (void)dev;
         |               ^~~
         |               pdev

drivers/virt/vmgenid.c:154:15: note: each undeclared identifier is reported only once for each function it appears in

vim +154 drivers/virt/vmgenid.c

121
122 static int vmgenid_add_of(struct platform_device *pdev, struct vmgenid_state *state)
123 {
124 #if IS_ENABLED(CONFIG_OF)
125 void __iomem *remapped_ptr;
126 int ret = 0;
127
128 remapped_ptr = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
129 if (IS_ERR(remapped_ptr)) {
130 ret = PTR_ERR(remapped_ptr);
131 goto out;
132 }
133
134 ret = setup_vmgenid_state(state, remapped_ptr);
135 if (ret)
136 goto out;
137
138 state->irq = platform_get_irq(pdev, 0);
139 if (state->irq < 0) {
140 ret = state->irq;
141 goto out;
142 }
143 pdev->dev.driver_data = state;
144
145 ret = devm_request_irq(&pdev->dev, state->irq,
146 vmgenid_of_irq_handler,
147 IRQF_SHARED, "vmgenid", &pdev->dev);
148 if (ret)
149 pdev->dev.driver_data = NULL;
150
151 out:
152 return ret;
153 #else

 > 154		(void)dev;

155 (void)state;
156 return -EINVAL;
157 #endif
158 }
159

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#13 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

Quoted 3 lines · kernel test robot

Hi Sudan,

kernel test robot noticed the following build errors:

...

Quoted 12 lines
   134		ret = setup_vmgenid_state(state, remapped_ptr);
   135		if (ret)
   136			goto out;
   137	
   138		state->irq = platform_get_irq(pdev, 0);
   139		if (state->irq < 0) {
   140			ret = state->irq;
   141			goto out;
   142		}
   143		pdev->dev.driver_data = state;
   144	
   145		ret =  devm_request_irq(&pdev->dev, state->irq,
Quoted 9 lines
   146					vmgenid_of_irq_handler,
   147					IRQF_SHARED, "vmgenid", &pdev->dev);
   148		if (ret)
   149			pdev->dev.driver_data = NULL;
   150	
   151	out:
   152		return ret;
   153	#else
Quoted 1 line

154 (void)dev;

So this code was not even built...

Best regards,
Krzysztof

#14 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

Quoted 33 lines · Krzysztof Kozlowski

CAUTION: This email originated from outside of the organization. Do not click links or open attachments unless you can confirm the sender and know the content is safe.

Quoted 3 lines · kernel test robot

Hi Sudan,

kernel test robot noticed the following build errors:

...

Quoted 12 lines
    134                ret = setup_vmgenid_state(state, remapped_ptr);
    135                if (ret)
    136                        goto out;
    137
    138                state->irq = platform_get_irq(pdev, 0);
    139                if (state->irq < 0) {
    140                        ret = state->irq;
    141                        goto out;
    142                }
    143                pdev->dev.driver_data = state;
    144
    145                ret =  devm_request_irq(&pdev->dev, state->irq,
Quoted 9 lines
    146                                        vmgenid_of_irq_handler,
    147                                        IRQF_SHARED, "vmgenid", &pdev->dev);
    148                if (ret)
    149                        pdev->dev.driver_data = NULL;
    150
    151        out:
    152                return ret;
    153        #else
Quoted 1 line

154 (void)dev;

Quoted 5 lines

So this code was not even built...

Best regards,
Krzysztof

I built it with CONFIG_ACPI and CONFIG_OF enabled but missed to build it without the CONFIG_OF flag. As mentioned in the other mail I'll make sure to run all required tools and check for all combinations before posting future patches.

#15 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

In reply to Sudan Landge
kernel test robot noticed the following build errors:

Hi Sudan,

kernel test robot noticed the following build errors:

[auto build test ERROR on 8e938e39866920ddc266898e6ae1fffc5c8f51aa]

url:    https://github.com/intel-lab-lkp/linux/commits/Sudan-Landge/virt-vmgenid-rearrange-code-to-make-review-easier/20240326-035657
base:   8e938e39866920ddc266898e6ae1fffc5c8f51aa
patch link:    https://lore.kernel.org/r/20240325195306.13133-5-sudanl%40amazon.com
patch subject: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings
config: x86_64-randconfig-161-20240326 (https://download.01.org/0day-ci/archive/20240326/[email protected]/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240326/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/virt/vmgenid.c:154:8: error: use of undeclared identifier 'dev'
     154 |         (void)dev;
         |               ^

1 error generated.

vim +/dev +154 drivers/virt/vmgenid.c

121
122 static int vmgenid_add_of(struct platform_device *pdev, struct vmgenid_state *state)
123 {
124 #if IS_ENABLED(CONFIG_OF)
125 void __iomem *remapped_ptr;
126 int ret = 0;
127
128 remapped_ptr = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
129 if (IS_ERR(remapped_ptr)) {
130 ret = PTR_ERR(remapped_ptr);
131 goto out;
132 }
133
134 ret = setup_vmgenid_state(state, remapped_ptr);
135 if (ret)
136 goto out;
137
138 state->irq = platform_get_irq(pdev, 0);
139 if (state->irq < 0) {
140 ret = state->irq;
141 goto out;
142 }
143 pdev->dev.driver_data = state;
144
145 ret = devm_request_irq(&pdev->dev, state->irq,
146 vmgenid_of_irq_handler,
147 IRQF_SHARED, "vmgenid", &pdev->dev);
148 if (ret)
149 pdev->dev.driver_data = NULL;
150
151 out:
152 return ret;
153 #else

 > 154		(void)dev;

155 (void)state;
156 return -EINVAL;
157 #endif
158 }
159

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#16 lore raw

Re: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings

In reply to Sudan Landge
kernel test robot noticed the following build warnings:

Hi Sudan,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 8e938e39866920ddc266898e6ae1fffc5c8f51aa]

url:    https://github.com/intel-lab-lkp/linux/commits/Sudan-Landge/virt-vmgenid-rearrange-code-to-make-review-easier/20240326-035657
base:   8e938e39866920ddc266898e6ae1fffc5c8f51aa
patch link:    https://lore.kernel.org/r/20240325195306.13133-5-sudanl%40amazon.com
patch subject: [PATCH v3 4/4] virt: vmgenid: add support for devicetree bindings
config: x86_64-buildonly-randconfig-004-20240326 (https://download.01.org/0day-ci/archive/20240327/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240327/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

drivers/virt/vmgenid.c: In function 'vmgenid_add_of':
drivers/virt/vmgenid.c:154:15: error: 'dev' undeclared (first use in this function); did you mean 'pdev'?

     154 |         (void)dev;
         |               ^~~
         |               pdev
   drivers/virt/vmgenid.c:154:15: note: each undeclared identifier is reported only once for each function it appears in
   drivers/virt/vmgenid.c: At top level:
>> drivers/virt/vmgenid.c:60:12: warning: 'setup_vmgenid_state' defined but not used [-Wunused-function]
      60 | static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
         |            ^~~~~~~~~~~~~~~~~~~
>> drivers/virt/vmgenid.c:27:13: warning: 'vmgenid_notify' defined but not used [-Wunused-function]

27 | static void vmgenid_notify(struct device *device)
| ^~~~~~~~~~~~~~

vim +/setup_vmgenid_state +60 drivers/virt/vmgenid.c

af6b54e2b5baa5 Jason A. Donenfeld 2022-02-23 26

fba2c3554a30ca Sudan Landge       2024-03-25 @27  static void vmgenid_notify(struct device *device)
5eb78dfcd888d3 Sudan Landge       2024-03-25  28  {
fba2c3554a30ca Sudan Landge       2024-03-25  29  	struct vmgenid_state *state = device->driver_data;
5eb78dfcd888d3 Sudan Landge       2024-03-25  30  	char *envp[] = { "NEW_VMGENID=1", NULL };
5eb78dfcd888d3 Sudan Landge       2024-03-25  31  	u8 old_id[VMGENID_SIZE];
5eb78dfcd888d3 Sudan Landge       2024-03-25  32  
5eb78dfcd888d3 Sudan Landge       2024-03-25  33  	memcpy(old_id, state->this_id, sizeof(old_id));
5eb78dfcd888d3 Sudan Landge       2024-03-25  34  	memcpy(state->this_id, state->next_id, sizeof(state->this_id));
5eb78dfcd888d3 Sudan Landge       2024-03-25  35  	if (!memcmp(old_id, state->this_id, sizeof(old_id)))
5eb78dfcd888d3 Sudan Landge       2024-03-25  36  		return;
5eb78dfcd888d3 Sudan Landge       2024-03-25  37  	add_vmfork_randomness(state->this_id, sizeof(state->this_id));
fba2c3554a30ca Sudan Landge       2024-03-25  38  	kobject_uevent_env(&device->kobj, KOBJ_CHANGE, envp);
5eb78dfcd888d3 Sudan Landge       2024-03-25  39  }
5eb78dfcd888d3 Sudan Landge       2024-03-25  40  
84d2b6732ae89f Sudan Landge       2024-03-25  41  #if IS_ENABLED(CONFIG_ACPI)
fba2c3554a30ca Sudan Landge       2024-03-25  42  static void vmgenid_acpi_handler(acpi_handle handle, u32 event, void *dev)
af6b54e2b5baa5 Jason A. Donenfeld 2022-02-23  43  {
84d2b6732ae89f Sudan Landge       2024-03-25  44  	(void)handle;
84d2b6732ae89f Sudan Landge       2024-03-25  45  	(void)event;
fba2c3554a30ca Sudan Landge       2024-03-25  46  	vmgenid_notify(dev);
fba2c3554a30ca Sudan Landge       2024-03-25  47  }
84d2b6732ae89f Sudan Landge       2024-03-25  48  #endif
84d2b6732ae89f Sudan Landge       2024-03-25  49  
84d2b6732ae89f Sudan Landge       2024-03-25  50  #if IS_ENABLED(CONFIG_OF)
84d2b6732ae89f Sudan Landge       2024-03-25  51  static irqreturn_t vmgenid_of_irq_handler(int irq, void *dev)
84d2b6732ae89f Sudan Landge       2024-03-25  52  {
84d2b6732ae89f Sudan Landge       2024-03-25  53  	(void)irq;
84d2b6732ae89f Sudan Landge       2024-03-25  54  	vmgenid_notify(dev);
84d2b6732ae89f Sudan Landge       2024-03-25  55  
84d2b6732ae89f Sudan Landge       2024-03-25  56  	return IRQ_HANDLED;
84d2b6732ae89f Sudan Landge       2024-03-25  57  }
84d2b6732ae89f Sudan Landge       2024-03-25  58  #endif
fba2c3554a30ca Sudan Landge       2024-03-25  59  
fba2c3554a30ca Sudan Landge       2024-03-25 @60  static int setup_vmgenid_state(struct vmgenid_state *state, u8 *next_id)
fba2c3554a30ca Sudan Landge       2024-03-25  61  {
fba2c3554a30ca Sudan Landge       2024-03-25  62  	if (IS_ERR(next_id))
fba2c3554a30ca Sudan Landge       2024-03-25  63  		return PTR_ERR(next_id);
fba2c3554a30ca Sudan Landge       2024-03-25  64  
fba2c3554a30ca Sudan Landge       2024-03-25  65  	state->next_id = next_id;
fba2c3554a30ca Sudan Landge       2024-03-25  66  	memcpy(state->this_id, state->next_id, sizeof(state->this_id));
fba2c3554a30ca Sudan Landge       2024-03-25  67  	add_device_randomness(state->this_id, sizeof(state->this_id));
fba2c3554a30ca Sudan Landge       2024-03-25  68  	return 0;
fba2c3554a30ca Sudan Landge       2024-03-25  69  }
fba2c3554a30ca Sudan Landge       2024-03-25  70  
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki