Skip to content

Commit 70916eb

Browse files
committed
ci: patch ARM 6.1 guest kernel with VMGenID support
Linux support for VMGenID on ARM systems landed in kernel 6.10. We only support up to kernel 6.1. So in order to be able to test VMGenID on ARM systems we need to patch our 6.1 kernel to backport the 6.10 commits. This commit adds the patches in our repo under `resources/patches/vmgenid_dt` and changes rebuild.sh to patch 6.1 kernel on ARM before building it. Also, it enables `CONFIG_VMGENID` for ARM 6.1 guest kernel. Eventually we will switch to using guest kernels from Amazon Linux trees hosted on Github, which they will eventually backport the relevant patches. Once this is done we can drop the patches from our tree and we won't need to manually patch them. Signed-off-by: Babis Chalios <[email protected]>
1 parent f45fa5e commit 70916eb

5 files changed

+462
-0
lines changed

resources/guest_configs/microvm-kernel-ci-aarch64-6.1.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,7 @@ CONFIG_CHARLCD_BL_FLASH=y
19431943
# CONFIG_UIO is not set
19441944
# CONFIG_VFIO is not set
19451945
CONFIG_VIRT_DRIVERS=y
1946+
CONFIG_VMGENID=y
19461947
CONFIG_VIRTIO=y
19471948
CONFIG_VIRTIO_MENU=y
19481949
CONFIG_VIRTIO_BALLOON=y
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
From 1e96eb7dd95b1908428195ef69a30effd562f947 Mon Sep 17 00:00:00 2001
2+
From: Sudan Landge <[email protected]>
3+
Date: Wed, 17 Apr 2024 12:40:42 +0200
4+
Subject: [PATCH 1/3] virt: vmgenid: change implementation to use a platform
5+
driver
6+
7+
Re-implement vmgenid as a platform driver in preparation for adding
8+
devicetree bindings support in next commits.
9+
10+
Signed-off-by: Sudan Landge <[email protected]>
11+
Reviewed-by: Alexander Graf <[email protected]>
12+
Tested-by: Babis Chalios <[email protected]>
13+
[Jason: - Small style cleanups and refactoring.]
14+
Signed-off-by: Jason A. Donenfeld <[email protected]>
15+
---
16+
drivers/virt/vmgenid.c | 99 +++++++++++++++++++++++++++---------------
17+
1 file changed, 65 insertions(+), 34 deletions(-)
18+
19+
diff --git a/drivers/virt/vmgenid.c b/drivers/virt/vmgenid.c
20+
index a1c467a0e9f71..0522107f9beeb 100644
21+
--- a/drivers/virt/vmgenid.c
22+
+++ b/drivers/virt/vmgenid.c
23+
@@ -7,9 +7,10 @@
24+
* information to random.c.
25+
*/
26+
27+
+#include <linux/acpi.h>
28+
#include <linux/kernel.h>
29+
#include <linux/module.h>
30+
-#include <linux/acpi.h>
31+
+#include <linux/platform_device.h>
32+
#include <linux/random.h>
33+
34+
ACPI_MODULE_NAME("vmgenid");
35+
@@ -21,19 +22,41 @@ struct vmgenid_state {
36+
u8 this_id[VMGENID_SIZE];
37+
};
38+
39+
-static int vmgenid_add(struct acpi_device *device)
40+
+static void vmgenid_notify(struct device *device)
41+
+{
42+
+ struct vmgenid_state *state = device->driver_data;
43+
+ u8 old_id[VMGENID_SIZE];
44+
+
45+
+ memcpy(old_id, state->this_id, sizeof(old_id));
46+
+ memcpy(state->this_id, state->next_id, sizeof(state->this_id));
47+
+ if (!memcmp(old_id, state->this_id, sizeof(old_id)))
48+
+ return;
49+
+ add_vmfork_randomness(state->this_id, sizeof(state->this_id));
50+
+}
51+
+
52+
+static void setup_vmgenid_state(struct vmgenid_state *state, void *virt_addr)
53+
{
54+
+ state->next_id = virt_addr;
55+
+ memcpy(state->this_id, state->next_id, sizeof(state->this_id));
56+
+ add_device_randomness(state->this_id, sizeof(state->this_id));
57+
+}
58+
+
59+
+static void vmgenid_acpi_handler(acpi_handle __always_unused handle,
60+
+ u32 __always_unused event, void *dev)
61+
+{
62+
+ vmgenid_notify(dev);
63+
+}
64+
+
65+
+static int vmgenid_add_acpi(struct device *dev, struct vmgenid_state *state)
66+
+{
67+
+ struct acpi_device *device = ACPI_COMPANION(dev);
68+
struct acpi_buffer parsed = { ACPI_ALLOCATE_BUFFER };
69+
- struct vmgenid_state *state;
70+
union acpi_object *obj;
71+
phys_addr_t phys_addr;
72+
acpi_status status;
73+
+ void *virt_addr;
74+
int ret = 0;
75+
76+
- state = devm_kmalloc(&device->dev, sizeof(*state), GFP_KERNEL);
77+
- if (!state)
78+
- return -ENOMEM;
79+
-
80+
status = acpi_evaluate_object(device->handle, "ADDR", NULL, &parsed);
81+
if (ACPI_FAILURE(status)) {
82+
ACPI_EXCEPTION((AE_INFO, status, "Evaluating ADDR"));
83+
@@ -49,53 +72,61 @@ static int vmgenid_add(struct acpi_device *device)
84+
85+
phys_addr = (obj->package.elements[0].integer.value << 0) |
86+
(obj->package.elements[1].integer.value << 32);
87+
- state->next_id = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, MEMREMAP_WB);
88+
- if (IS_ERR(state->next_id)) {
89+
- ret = PTR_ERR(state->next_id);
90+
+
91+
+ virt_addr = devm_memremap(&device->dev, phys_addr, VMGENID_SIZE, MEMREMAP_WB);
92+
+ if (IS_ERR(virt_addr)) {
93+
+ ret = PTR_ERR(virt_addr);
94+
goto out;
95+
}
96+
+ setup_vmgenid_state(state, virt_addr);
97+
98+
- memcpy(state->this_id, state->next_id, sizeof(state->this_id));
99+
- add_device_randomness(state->this_id, sizeof(state->this_id));
100+
-
101+
- device->driver_data = state;
102+
+ status = acpi_install_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
103+
+ vmgenid_acpi_handler, dev);
104+
+ if (ACPI_FAILURE(status)) {
105+
+ ret = -ENODEV;
106+
+ goto out;
107+
+ }
108+
109+
+ dev->driver_data = state;
110+
out:
111+
ACPI_FREE(parsed.pointer);
112+
return ret;
113+
}
114+
115+
-static void vmgenid_notify(struct acpi_device *device, u32 event)
116+
+static int vmgenid_add(struct platform_device *pdev)
117+
{
118+
- struct vmgenid_state *state = acpi_driver_data(device);
119+
- u8 old_id[VMGENID_SIZE];
120+
+ struct device *dev = &pdev->dev;
121+
+ struct vmgenid_state *state;
122+
+ int ret;
123+
124+
- memcpy(old_id, state->this_id, sizeof(old_id));
125+
- memcpy(state->this_id, state->next_id, sizeof(state->this_id));
126+
- if (!memcmp(old_id, state->this_id, sizeof(old_id)))
127+
- return;
128+
- add_vmfork_randomness(state->this_id, sizeof(state->this_id));
129+
+ state = devm_kmalloc(dev, sizeof(*state), GFP_KERNEL);
130+
+ if (!state)
131+
+ return -ENOMEM;
132+
+
133+
+ ret = vmgenid_add_acpi(dev, state);
134+
+
135+
+ if (ret < 0)
136+
+ devm_kfree(dev, state);
137+
+ return ret;
138+
}
139+
140+
-static const struct acpi_device_id vmgenid_ids[] = {
141+
+static const struct acpi_device_id vmgenid_acpi_ids[] = {
142+
{ "VMGENCTR", 0 },
143+
{ "VM_GEN_COUNTER", 0 },
144+
{ }
145+
};
146+
-
147+
-static struct acpi_driver vmgenid_driver = {
148+
- .name = "vmgenid",
149+
- .ids = vmgenid_ids,
150+
- .owner = THIS_MODULE,
151+
- .ops = {
152+
- .add = vmgenid_add,
153+
- .notify = vmgenid_notify
154+
- }
155+
+MODULE_DEVICE_TABLE(acpi, vmgenid_acpi_ids);
156+
+
157+
+static struct platform_driver vmgenid_plaform_driver = {
158+
+ .probe = vmgenid_add,
159+
+ .driver = {
160+
+ .name = "vmgenid",
161+
+ .acpi_match_table = vmgenid_acpi_ids,
162+
+ },
163+
};
164+
165+
-module_acpi_driver(vmgenid_driver);
166+
+module_platform_driver(vmgenid_plaform_driver)
167+
168+
-MODULE_DEVICE_TABLE(acpi, vmgenid_ids);
169+
MODULE_DESCRIPTION("Virtual Machine Generation ID");
170+
MODULE_LICENSE("GPL v2");
171+
MODULE_AUTHOR("Jason A. Donenfeld <[email protected]>");
172+
--
173+
2.34.1
174+
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
From 477bd33715e9d669bc3d5968cd69108241ae099c Mon Sep 17 00:00:00 2001
2+
From: Sudan Landge <[email protected]>
3+
Date: Wed, 17 Apr 2024 12:40:45 +0200
4+
Subject: [PATCH 2/3] dt-bindings: rng: Add vmgenid support
5+
6+
Virtual Machine Generation ID driver was introduced in commit
7+
af6b54e2b5ba ("virt: vmgenid: notify RNG of VM fork and supply
8+
generation ID"), as an ACPI only device.
9+
10+
VMGenID specification http://go.microsoft.com/fwlink/?LinkId=260709
11+
defines a mechanism for the BIOS/hypervisors to communicate to the
12+
virtual machine that it is executed with a different configuration (e.g.
13+
snapshot execution or creation from a template). The guest operating
14+
system can use the notification for various purposes such as
15+
re-initializing its random number generator etc.
16+
17+
As per the specs, hypervisor should provide a globally unique
18+
identified, or GUID via ACPI.
19+
20+
This patch tries to mimic the mechanism to provide the same
21+
functionality which is for a hypervisor/BIOS to notify the virtual
22+
machine when it is executed with a different configuration.
23+
24+
As part of this support the devicetree bindings requires the hypervisors
25+
or BIOS to provide a memory address which holds the GUID and an IRQ
26+
which is used to notify when there is a change in the GUID. The memory
27+
exposed in the DT should follow the rules defined in the vmgenid spec
28+
mentioned above.
29+
30+
Reason for this change: Chosing ACPI or devicetree is an intrinsic part
31+
of an hypervisor design. Without going into details of why a hypervisor
32+
would chose DT over ACPI, we would like to highlight that the
33+
hypervisors that have chose devicetree and now want to make use of the
34+
vmgenid functionality cannot do so today because vmgenid is an ACPI only
35+
device. This forces these hypervisors to change their design which
36+
could have undesirable impacts on their use-cases, test-scenarios etc.
37+
38+
The point of vmgenid is to provide a mechanism to discover a GUID when
39+
the execution state of a virtual machine changes and the simplest way to
40+
do it is pass a memory location and an interrupt via devicetree. It
41+
would complicate things unnecessarily if instead of using devicetree, we
42+
try to implement a new protocol or modify other protocols to somehow
43+
provide the same functionility.
44+
45+
We believe that adding a devicetree binding for vmgenid is a simpler,
46+
better alternative to provide the same functionality and will allow such
47+
hypervisors as mentioned above to continue using devicetree.
48+
49+
More references to the vmgenid specs are found below.
50+
51+
Signed-off-by: Sudan Landge <[email protected]>
52+
Reviewed-by: Rob Herring <[email protected]>
53+
Reviewed-by: Alexander Graf <[email protected]>
54+
Link: https://www.qemu.org/docs/master/specs/vmgenid.html
55+
Link: https://learn.microsoft.com/en-us/windows/win32/hyperv_v2/virtual-machine-generation-identifier
56+
Signed-off-by: Jason A. Donenfeld <[email protected]>
57+
---
58+
.../bindings/rng/microsoft,vmgenid.yaml | 49 +++++++++++++++++++
59+
MAINTAINERS | 3 +-
60+
2 files changed, 51 insertions(+), 1 deletion(-)
61+
create mode 100644 Documentation/devicetree/bindings/rng/microsoft,vmgenid.yaml
62+
63+
diff --git a/Documentation/devicetree/bindings/rng/microsoft,vmgenid.yaml b/Documentation/devicetree/bindings/rng/microsoft,vmgenid.yaml
64+
new file mode 100644
65+
index 0000000000000..8f20dee93e7ea
66+
--- /dev/null
67+
+++ b/Documentation/devicetree/bindings/rng/microsoft,vmgenid.yaml
68+
@@ -0,0 +1,49 @@
69+
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
70+
+%YAML 1.2
71+
+---
72+
+$id: http://devicetree.org/schemas/rng/microsoft,vmgenid.yaml#
73+
+$schema: http://devicetree.org/meta-schemas/core.yaml#
74+
+
75+
+title: Virtual Machine Generation ID
76+
+
77+
+maintainers:
78+
+ - Jason A. Donenfeld <[email protected]>
79+
+
80+
+description:
81+
+ Firmwares or hypervisors can use this devicetree to describe an
82+
+ interrupt and a shared resource to inject a Virtual Machine Generation ID.
83+
+ Virtual Machine Generation ID is a globally unique identifier (GUID) and
84+
+ the devicetree binding follows VMGenID specification defined in
85+
+ http://go.microsoft.com/fwlink/?LinkId=260709.
86+
+
87+
+properties:
88+
+ compatible:
89+
+ const: microsoft,vmgenid
90+
+
91+
+ reg:
92+
+ description:
93+
+ Specifies a 16-byte VMGenID in endianness-agnostic hexadecimal format.
94+
+ maxItems: 1
95+
+
96+
+ interrupts:
97+
+ description:
98+
+ Interrupt used to notify that a new VMGenID is available.
99+
+ maxItems: 1
100+
+
101+
+required:
102+
+ - compatible
103+
+ - reg
104+
+ - interrupts
105+
+
106+
+additionalProperties: false
107+
+
108+
+examples:
109+
+ - |
110+
+ #include <dt-bindings/interrupt-controller/arm-gic.h>
111+
+ rng@80000000 {
112+
+ compatible = "microsoft,vmgenid";
113+
+ reg = <0x80000000 0x1000>;
114+
+ interrupts = <GIC_SPI 35 IRQ_TYPE_EDGE_RISING>;
115+
+ };
116+
+
117+
+...
118+
diff --git a/MAINTAINERS b/MAINTAINERS
119+
index 886d3f69ee644..792d1a8b6f422 100644
120+
--- a/MAINTAINERS
121+
+++ b/MAINTAINERS
122+
@@ -17290,8 +17290,9 @@ F: arch/mips/generic/board-ranchu.c
123+
RANDOM NUMBER DRIVER
124+
M: "Theodore Ts'o" <[email protected]>
125+
M: Jason A. Donenfeld <[email protected]>
126+
-T: git https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git
127+
S: Maintained
128+
+T: git https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git
129+
+F: Documentation/devicetree/bindings/rng/microsoft,vmgenid.yaml
130+
F: drivers/char/random.c
131+
F: drivers/virt/vmgenid.c
132+
133+
--
134+
2.34.1
135+

0 commit comments

Comments
 (0)