From: Or Idgar <[email protected]>
This patch is a driver which expose the Virtual Machine Generation ID
via sysfs. The ID is a UUID value used to differentiate between virtual
machines.
The VM-Generation ID is a feature defined by Microsoft (paper:
http://go.microsoft.com/fwlink/?LinkId=260709) and supported by multiple
hypervisor vendors.
Signed-off-by: Or Idgar <[email protected]>
---
Documentation/ABI/testing/sysfs-hypervisor | 13 +++
drivers/misc/Kconfig | 6 ++
drivers/misc/Makefile | 1 +
drivers/misc/vmgenid.c | 141 +++++++++++++++++++++++++++++
4 files changed, 161 insertions(+)
create mode 100644 Documentation/ABI/testing/sysfs-hypervisor
create mode 100644 drivers/misc/vmgenid.c
diff --git a/Documentation/ABI/testing/sysfs-hypervisor b/Documentation/ABI/testing/sysfs-hypervisor
new file mode 100644
index 000000000000..2f9a7b8eab70
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-hypervisor
@@ -0,0 +1,13 @@
+What: /sys/hypervisor/vm_gen_counter
+Date: February 2018
+Contact: Or Idgar <[email protected]>
+ Gal Hammer <[email protected]>
+Description: Expose the virtual machine generation ID. The directory
+ contains two files: "generation_id" and "raw". Both files
+ represent the same information.
+
+ "generation_id" file is a UUID string
+ representation.
+
+ "raw" file is a 128-bit integer
+ representation (binary).
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 03605f8fc0dc..5a74802bdfb4 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -500,6 +500,12 @@ config MISC_RTSX
tristate
default MISC_RTSX_PCI || MISC_RTSX_USB
+config VMGENID
+ tristate "Virtual Machine Generation ID driver"
+ help
+ This is a Virtual Machine Generation ID driver which provides
+ a virtual machine unique identifier.
+
source "drivers/misc/c2port/Kconfig"
source "drivers/misc/eeprom/Kconfig"
source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index c3c8624f4d95..067aa666bb6a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -57,6 +57,7 @@ obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o
obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o
obj-$(CONFIG_OCXL) += ocxl/
obj-$(CONFIG_MISC_RTSX) += cardreader/
+obj-$(CONFIG_VMGENID) += vmgenid.o
lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o
lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o
diff --git a/drivers/misc/vmgenid.c b/drivers/misc/vmgenid.c
new file mode 100644
index 000000000000..9d7f09f9e7bd
--- /dev/null
+++ b/drivers/misc/vmgenid.c
@@ -0,0 +1,141 @@
+/*
+ * Virtual Machine Generation ID driver
+ *
+ * Copyright (C) 2018 Red Hat, Inc. All rights reserved.
+ * Authors:
+ * Or Idgar <[email protected]>
+ * Gal Hammer <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/acpi.h>
+#include <linux/uuid.h>
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Or Idgar <[email protected]>");
+MODULE_AUTHOR("Gal Hammer <[email protected]>");
+MODULE_DESCRIPTION("Virtual Machine Generation ID");
+MODULE_VERSION("0.1");
+
+ACPI_MODULE_NAME("vmgenid");
+
+static u64 phy_addr;
+
+static ssize_t generation_id_show(struct device *_d,
+ struct device_attribute *attr, char *buf)
+{
+ uuid_t *uuidp;
+ ssize_t result;
+
+ uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
+ if (!uuidp)
+ return -EFAULT;
+
+ result = sprintf(buf, "%pUl\n", uuidp);
+ acpi_os_unmap_iomem(uuidp, sizeof(uuid_t));
+ return result;
+}
+static DEVICE_ATTR_RO(generation_id);
+
+static ssize_t raw_show(struct device *_d,
+ struct device_attribute *attr,
+ char *buf)
+{
+ uuid_t *uuidp;
+
+ uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
+ if (!uuidp)
+ return -EFAULT;
+ memcpy(buf, uuidp, sizeof(uuid_t));
+ acpi_os_unmap_iomem(uuidp, sizeof(uuid_t));
+ return sizeof(uuid_t);
+}
+static DEVICE_ATTR_RO(raw);
+
+static struct attribute *vmgenid_attrs[] = {
+ &dev_attr_generation_id.attr,
+ &dev_attr_raw.attr,
+ NULL,
+};
+static const struct attribute_group vmgenid_group = {
+ .name = "vm_gen_counter",
+ .attrs = vmgenid_attrs,
+};
+
+static int get_vmgenid(acpi_handle handle)
+{
+ int i;
+ struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
+ acpi_status status;
+ union acpi_object *pss;
+ union acpi_object *element;
+
+ status = acpi_evaluate_object(handle, "ADDR", NULL, &buffer);
+ if (ACPI_FAILURE(status)) {
+ ACPI_EXCEPTION((AE_INFO, status, "Evaluating _ADDR"));
+ return -ENODEV;
+ }
+ pss = buffer.pointer;
+ if (!pss || pss->type != ACPI_TYPE_PACKAGE || pss->package.count != 2)
+ return -EFAULT;
+
+ phy_addr = 0;
+ for (i = 0; i < pss->package.count; i++) {
+ element = &(pss->package.elements[i]);
+ if (element->type != ACPI_TYPE_INTEGER)
+ return -EFAULT;
+ phy_addr |= element->integer.value << i*32;
+ }
+ return 0;
+}
+
+static int acpi_vmgenid_add(struct acpi_device *device)
+{
+ int retval;
+
+ if (!device)
+ return -EINVAL;
+ retval = get_vmgenid(device->handle);
+ if (retval < 0)
+ return retval;
+ return sysfs_create_group(hypervisor_kobj, &vmgenid_group);
+}
+
+static int acpi_vmgenid_remove(struct acpi_device *device)
+{
+ sysfs_remove_group(hypervisor_kobj, &vmgenid_group);
+ return 0;
+}
+
+static const struct acpi_device_id vmgenid_ids[] = {
+ {"QEMUVGID", 0},
+ {"", 0},
+};
+
+static struct acpi_driver acpi_vmgenid_driver = {
+ .name = "vm_gen_counter",
+ .ids = vmgenid_ids,
+ .owner = THIS_MODULE,
+ .ops = {
+ .add = acpi_vmgenid_add,
+ .remove = acpi_vmgenid_remove,
+ }
+};
+
+static int __init vmgenid_init(void)
+{
+ return acpi_bus_register_driver(&acpi_vmgenid_driver);
+}
+
+static void __exit vmgenid_exit(void)
+{
+ acpi_bus_unregister_driver(&acpi_vmgenid_driver);
+}
+
+module_init(vmgenid_init);
+module_exit(vmgenid_exit);
--
2.14.3
On Thu, Feb 22, 2018 at 06:20:38PM +0200, Or Idgar wrote:
> From: Or Idgar <[email protected]>
>
> This patch is a driver which expose the Virtual Machine Generation ID
> via sysfs. The ID is a UUID value used to differentiate between virtual
> machines.
>
> The VM-Generation ID is a feature defined by Microsoft (paper:
> http://go.microsoft.com/fwlink/?LinkId=260709) and supported by multiple
> hypervisor vendors.
>
> Signed-off-by: Or Idgar <[email protected]>
> ---
> Documentation/ABI/testing/sysfs-hypervisor | 13 +++
> drivers/misc/Kconfig | 6 ++
> drivers/misc/Makefile | 1 +
> drivers/misc/vmgenid.c | 141 +++++++++++++++++++++++++++++
> 4 files changed, 161 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-hypervisor
> create mode 100644 drivers/misc/vmgenid.c
>
> diff --git a/Documentation/ABI/testing/sysfs-hypervisor b/Documentation/ABI/testing/sysfs-hypervisor
> new file mode 100644
> index 000000000000..2f9a7b8eab70
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-hypervisor
> @@ -0,0 +1,13 @@
> +What: /sys/hypervisor/vm_gen_counter
Shouldn't this go under the specific hypervisor you are running on? Why
in the "root" of /sys/hypervisor?
> +Date: February 2018
> +Contact: Or Idgar <[email protected]>
> + Gal Hammer <[email protected]>
> +Description: Expose the virtual machine generation ID. The directory
> + contains two files: "generation_id" and "raw". Both files
> + represent the same information.
> +
> + "generation_id" file is a UUID string
> + representation.
> +
> + "raw" file is a 128-bit integer
> + representation (binary).
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index 03605f8fc0dc..5a74802bdfb4 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -500,6 +500,12 @@ config MISC_RTSX
> tristate
> default MISC_RTSX_PCI || MISC_RTSX_USB
>
> +config VMGENID
> + tristate "Virtual Machine Generation ID driver"
> + help
> + This is a Virtual Machine Generation ID driver which provides
> + a virtual machine unique identifier.
> +
> source "drivers/misc/c2port/Kconfig"
> source "drivers/misc/eeprom/Kconfig"
> source "drivers/misc/cb710/Kconfig"
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index c3c8624f4d95..067aa666bb6a 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -57,6 +57,7 @@ obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o
> obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o
> obj-$(CONFIG_OCXL) += ocxl/
> obj-$(CONFIG_MISC_RTSX) += cardreader/
> +obj-$(CONFIG_VMGENID) += vmgenid.o
>
> lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o
> lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o
> diff --git a/drivers/misc/vmgenid.c b/drivers/misc/vmgenid.c
> new file mode 100644
> index 000000000000..9d7f09f9e7bd
> --- /dev/null
> +++ b/drivers/misc/vmgenid.c
> @@ -0,0 +1,141 @@
> +/*
> + * Virtual Machine Generation ID driver
> + *
> + * Copyright (C) 2018 Red Hat, Inc. All rights reserved.
> + * Authors:
> + * Or Idgar <[email protected]>
> + * Gal Hammer <[email protected]>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
No SPDX line? Please see the documentation for how to properly add this
as the first line of any new file.
I want some hypervisor people to weigh in on this before I can take
it...
thanks,
greg k-h
Hi,
On Thu, Feb 22, 2018 at 6:36 PM, Greg KH <[email protected]> wrote:
> On Thu, Feb 22, 2018 at 06:20:38PM +0200, Or Idgar wrote:
>> From: Or Idgar <[email protected]>
>>
>> This patch is a driver which expose the Virtual Machine Generation ID
>> via sysfs. The ID is a UUID value used to differentiate between virtual
>> machines.
>>
>> The VM-Generation ID is a feature defined by Microsoft (paper:
>> http://go.microsoft.com/fwlink/?LinkId=260709) and supported by multiple
>> hypervisor vendors.
>>
>> Signed-off-by: Or Idgar <[email protected]>
>> ---
>> Documentation/ABI/testing/sysfs-hypervisor | 13 +++
>> drivers/misc/Kconfig | 6 ++
>> drivers/misc/Makefile | 1 +
>> drivers/misc/vmgenid.c | 141 +++++++++++++++++++++++++++++
>> 4 files changed, 161 insertions(+)
>> create mode 100644 Documentation/ABI/testing/sysfs-hypervisor
>> create mode 100644 drivers/misc/vmgenid.c
>>
>> diff --git a/Documentation/ABI/testing/sysfs-hypervisor b/Documentation/ABI/testing/sysfs-hypervisor
>> new file mode 100644
>> index 000000000000..2f9a7b8eab70
>> --- /dev/null
>> +++ b/Documentation/ABI/testing/sysfs-hypervisor
>> @@ -0,0 +1,13 @@
>> +What: /sys/hypervisor/vm_gen_counter
>
> Shouldn't this go under the specific hypervisor you are running on? Why
> in the "root" of /sys/hypervisor?
As far as I know, most of today's hypervisors support this feature, so
adding a subdirectory doesn't seem right. The guest user should be
able to access the UUID without a knowledge of the running host.
At the moment, the driver supports only QEMU, but we're planning to
enhance it once we'll have access to other vendor hypervisors.
>
>> +Date: February 2018
>> +Contact: Or Idgar <[email protected]>
>> + Gal Hammer <[email protected]>
>> +Description: Expose the virtual machine generation ID. The directory
>> + contains two files: "generation_id" and "raw". Both files
>> + represent the same information.
>> +
>> + "generation_id" file is a UUID string
>> + representation.
>> +
>> + "raw" file is a 128-bit integer
>> + representation (binary).
>> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
>> index 03605f8fc0dc..5a74802bdfb4 100644
>> --- a/drivers/misc/Kconfig
>> +++ b/drivers/misc/Kconfig
>> @@ -500,6 +500,12 @@ config MISC_RTSX
>> tristate
>> default MISC_RTSX_PCI || MISC_RTSX_USB
>>
>> +config VMGENID
>> + tristate "Virtual Machine Generation ID driver"
>> + help
>> + This is a Virtual Machine Generation ID driver which provides
>> + a virtual machine unique identifier.
>> +
>> source "drivers/misc/c2port/Kconfig"
>> source "drivers/misc/eeprom/Kconfig"
>> source "drivers/misc/cb710/Kconfig"
>> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
>> index c3c8624f4d95..067aa666bb6a 100644
>> --- a/drivers/misc/Makefile
>> +++ b/drivers/misc/Makefile
>> @@ -57,6 +57,7 @@ obj-$(CONFIG_ASPEED_LPC_SNOOP) += aspeed-lpc-snoop.o
>> obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o
>> obj-$(CONFIG_OCXL) += ocxl/
>> obj-$(CONFIG_MISC_RTSX) += cardreader/
>> +obj-$(CONFIG_VMGENID) += vmgenid.o
>>
>> lkdtm-$(CONFIG_LKDTM) += lkdtm_core.o
>> lkdtm-$(CONFIG_LKDTM) += lkdtm_bugs.o
>> diff --git a/drivers/misc/vmgenid.c b/drivers/misc/vmgenid.c
>> new file mode 100644
>> index 000000000000..9d7f09f9e7bd
>> --- /dev/null
>> +++ b/drivers/misc/vmgenid.c
>> @@ -0,0 +1,141 @@
>> +/*
>> + * Virtual Machine Generation ID driver
>> + *
>> + * Copyright (C) 2018 Red Hat, Inc. All rights reserved.
>> + * Authors:
>> + * Or Idgar <[email protected]>
>> + * Gal Hammer <[email protected]>
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>
> No SPDX line? Please see the documentation for how to properly add this
> as the first line of any new file.
We'll give it another try.
> I want some hypervisor people to weigh in on this before I can take
> it...
>
> thanks,
>
> greg k-h
Thank you.
Gal.
Hi Or,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.16-rc2 next-20180223]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Or-Idgar/drivers-virt-vm_gen_counter-initial-driver-implementation/20180224-112017
config: sh-allmodconfig (attached as .config)
compiler: sh4-linux-gnu-gcc (Debian 7.2.0-11) 7.2.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=sh
All error/warnings (new ones prefixed by >>):
drivers/misc/vmgenid.c: In function 'generation_id_show':
>> drivers/misc/vmgenid.c:35:10: error: implicit declaration of function 'acpi_os_map_iomem'; did you mean 'acpi_os_read_iomem'? [-Werror=implicit-function-declaration]
uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
^~~~~~~~~~~~~~~~~
acpi_os_read_iomem
>> drivers/misc/vmgenid.c:35:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
^
>> drivers/misc/vmgenid.c:40:2: error: implicit declaration of function 'acpi_os_unmap_iomem'; did you mean 'acpi_os_read_iomem'? [-Werror=implicit-function-declaration]
acpi_os_unmap_iomem(uuidp, sizeof(uuid_t));
^~~~~~~~~~~~~~~~~~~
acpi_os_read_iomem
drivers/misc/vmgenid.c: In function 'raw_show':
drivers/misc/vmgenid.c:51:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
^
drivers/misc/vmgenid.c: In function 'acpi_vmgenid_add':
>> drivers/misc/vmgenid.c:103:29: error: dereferencing pointer to incomplete type 'struct acpi_device'
retval = get_vmgenid(device->handle);
^~
drivers/misc/vmgenid.c: At top level:
>> drivers/misc/vmgenid.c:115:36: error: array type has incomplete element type 'struct acpi_device_id'
static const struct acpi_device_id vmgenid_ids[] = {
^~~~~~~~~~~
>> drivers/misc/vmgenid.c:120:15: error: variable 'acpi_vmgenid_driver' has initializer but incomplete type
static struct acpi_driver acpi_vmgenid_driver = {
^~~~~~~~~~~
>> drivers/misc/vmgenid.c:121:3: error: 'struct acpi_driver' has no member named 'name'
.name = "vm_gen_counter",
^~~~
>> drivers/misc/vmgenid.c:121:10: warning: excess elements in struct initializer
.name = "vm_gen_counter",
^~~~~~~~~~~~~~~~
drivers/misc/vmgenid.c:121:10: note: (near initialization for 'acpi_vmgenid_driver')
>> drivers/misc/vmgenid.c:122:3: error: 'struct acpi_driver' has no member named 'ids'
.ids = vmgenid_ids,
^~~
drivers/misc/vmgenid.c:122:9: warning: excess elements in struct initializer
.ids = vmgenid_ids,
^~~~~~~~~~~
drivers/misc/vmgenid.c:122:9: note: (near initialization for 'acpi_vmgenid_driver')
>> drivers/misc/vmgenid.c:123:3: error: 'struct acpi_driver' has no member named 'owner'
.owner = THIS_MODULE,
^~~~~
In file included from include/linux/linkage.h:7:0,
from include/linux/kernel.h:7,
from include/linux/list.h:9,
from include/linux/module.h:9,
from drivers/misc/vmgenid.c:14:
include/linux/export.h:35:21: warning: excess elements in struct initializer
#define THIS_MODULE (&__this_module)
^
>> drivers/misc/vmgenid.c:123:11: note: in expansion of macro 'THIS_MODULE'
.owner = THIS_MODULE,
^~~~~~~~~~~
include/linux/export.h:35:21: note: (near initialization for 'acpi_vmgenid_driver')
#define THIS_MODULE (&__this_module)
^
>> drivers/misc/vmgenid.c:123:11: note: in expansion of macro 'THIS_MODULE'
.owner = THIS_MODULE,
^~~~~~~~~~~
>> drivers/misc/vmgenid.c:124:3: error: 'struct acpi_driver' has no member named 'ops'
.ops = {
^~~
>> drivers/misc/vmgenid.c:124:9: error: extra brace group at end of initializer
.ops = {
^
drivers/misc/vmgenid.c:124:9: note: (near initialization for 'acpi_vmgenid_driver')
drivers/misc/vmgenid.c:124:9: warning: excess elements in struct initializer
drivers/misc/vmgenid.c:124:9: note: (near initialization for 'acpi_vmgenid_driver')
drivers/misc/vmgenid.c: In function 'vmgenid_init':
>> drivers/misc/vmgenid.c:132:9: error: implicit declaration of function 'acpi_bus_register_driver'; did you mean 'acpi_nvs_register'? [-Werror=implicit-function-declaration]
return acpi_bus_register_driver(&acpi_vmgenid_driver);
^~~~~~~~~~~~~~~~~~~~~~~~
acpi_nvs_register
drivers/misc/vmgenid.c: In function 'vmgenid_exit':
>> drivers/misc/vmgenid.c:137:2: error: implicit declaration of function 'acpi_bus_unregister_driver'; did you mean 'bus_unregister_notifier'? [-Werror=implicit-function-declaration]
acpi_bus_unregister_driver(&acpi_vmgenid_driver);
^~~~~~~~~~~~~~~~~~~~~~~~~~
bus_unregister_notifier
drivers/misc/vmgenid.c: At top level:
>> drivers/misc/vmgenid.c:120:27: error: storage size of 'acpi_vmgenid_driver' isn't known
static struct acpi_driver acpi_vmgenid_driver = {
^~~~~~~~~~~~~~~~~~~
drivers/misc/vmgenid.c:115:36: warning: 'vmgenid_ids' defined but not used [-Wunused-variable]
static const struct acpi_device_id vmgenid_ids[] = {
^~~~~~~~~~~
cc1: some warnings being treated as errors
vim +35 drivers/misc/vmgenid.c
> 14 #include <linux/module.h>
15 #include <linux/kernel.h>
16 #include <linux/acpi.h>
17 #include <linux/uuid.h>
18
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Or Idgar <[email protected]>");
21 MODULE_AUTHOR("Gal Hammer <[email protected]>");
22 MODULE_DESCRIPTION("Virtual Machine Generation ID");
23 MODULE_VERSION("0.1");
24
25 ACPI_MODULE_NAME("vmgenid");
26
27 static u64 phy_addr;
28
29 static ssize_t generation_id_show(struct device *_d,
30 struct device_attribute *attr, char *buf)
31 {
32 uuid_t *uuidp;
33 ssize_t result;
34
> 35 uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
36 if (!uuidp)
37 return -EFAULT;
38
39 result = sprintf(buf, "%pUl\n", uuidp);
> 40 acpi_os_unmap_iomem(uuidp, sizeof(uuid_t));
41 return result;
42 }
43 static DEVICE_ATTR_RO(generation_id);
44
45 static ssize_t raw_show(struct device *_d,
46 struct device_attribute *attr,
47 char *buf)
48 {
49 uuid_t *uuidp;
50
> 51 uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
52 if (!uuidp)
53 return -EFAULT;
54 memcpy(buf, uuidp, sizeof(uuid_t));
55 acpi_os_unmap_iomem(uuidp, sizeof(uuid_t));
56 return sizeof(uuid_t);
57 }
58 static DEVICE_ATTR_RO(raw);
59
60 static struct attribute *vmgenid_attrs[] = {
61 &dev_attr_generation_id.attr,
62 &dev_attr_raw.attr,
63 NULL,
64 };
65 static const struct attribute_group vmgenid_group = {
66 .name = "vm_gen_counter",
67 .attrs = vmgenid_attrs,
68 };
69
70 static int get_vmgenid(acpi_handle handle)
71 {
72 int i;
73 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
74 acpi_status status;
75 union acpi_object *pss;
76 union acpi_object *element;
77
78 status = acpi_evaluate_object(handle, "ADDR", NULL, &buffer);
79 if (ACPI_FAILURE(status)) {
80 ACPI_EXCEPTION((AE_INFO, status, "Evaluating _ADDR"));
81 return -ENODEV;
82 }
83 pss = buffer.pointer;
84 if (!pss || pss->type != ACPI_TYPE_PACKAGE || pss->package.count != 2)
85 return -EFAULT;
86
87 phy_addr = 0;
88 for (i = 0; i < pss->package.count; i++) {
89 element = &(pss->package.elements[i]);
90 if (element->type != ACPI_TYPE_INTEGER)
91 return -EFAULT;
92 phy_addr |= element->integer.value << i*32;
93 }
94 return 0;
95 }
96
97 static int acpi_vmgenid_add(struct acpi_device *device)
98 {
99 int retval;
100
101 if (!device)
102 return -EINVAL;
> 103 retval = get_vmgenid(device->handle);
104 if (retval < 0)
105 return retval;
106 return sysfs_create_group(hypervisor_kobj, &vmgenid_group);
107 }
108
109 static int acpi_vmgenid_remove(struct acpi_device *device)
110 {
111 sysfs_remove_group(hypervisor_kobj, &vmgenid_group);
112 return 0;
113 }
114
> 115 static const struct acpi_device_id vmgenid_ids[] = {
116 {"QEMUVGID", 0},
117 {"", 0},
118 };
119
> 120 static struct acpi_driver acpi_vmgenid_driver = {
> 121 .name = "vm_gen_counter",
> 122 .ids = vmgenid_ids,
> 123 .owner = THIS_MODULE,
> 124 .ops = {
125 .add = acpi_vmgenid_add,
126 .remove = acpi_vmgenid_remove,
127 }
128 };
129
130 static int __init vmgenid_init(void)
131 {
> 132 return acpi_bus_register_driver(&acpi_vmgenid_driver);
133 }
134
135 static void __exit vmgenid_exit(void)
136 {
> 137 acpi_bus_unregister_driver(&acpi_vmgenid_driver);
138 }
139
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi Or,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on char-misc/char-misc-testing]
[also build test WARNING on v4.16-rc2 next-20180223]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Or-Idgar/drivers-virt-vm_gen_counter-initial-driver-implementation/20180224-112017
reproduce:
# apt-get install sparse
make ARCH=x86_64 allmodconfig
make C=1 CF=-D__CHECK_ENDIAN__
sparse warnings: (new ones prefixed by >>)
>> drivers/misc/vmgenid.c:35:15: sparse: incorrect type in assignment (different address spaces) @@ expected struct uuid_t @@ got uct uuid_t @@
drivers/misc/vmgenid.c:35:15: expected struct uuid_t
drivers/misc/vmgenid.c:35:15: got void
>> drivers/misc/vmgenid.c:40:29: sparse: incorrect type in argument 1 (different address spaces) @@ expected void @@ got strvoid @@
drivers/misc/vmgenid.c:40:29: expected void
drivers/misc/vmgenid.c:40:29: got struct uuid_t
drivers/misc/vmgenid.c:51:15: sparse: incorrect type in assignment (different address spaces) @@ expected struct uuid_t @@ got uct uuid_t @@
drivers/misc/vmgenid.c:51:15: expected struct uuid_t
drivers/misc/vmgenid.c:51:15: got void
drivers/misc/vmgenid.c:55:29: sparse: incorrect type in argument 1 (different address spaces) @@ expected void @@ got strvoid @@
drivers/misc/vmgenid.c:55:29: expected void
drivers/misc/vmgenid.c:55:29: got struct uuid_t
vim +35 drivers/misc/vmgenid.c
28
29 static ssize_t generation_id_show(struct device *_d,
30 struct device_attribute *attr, char *buf)
31 {
32 uuid_t *uuidp;
33 ssize_t result;
34
> 35 uuidp = acpi_os_map_iomem(phy_addr, sizeof(uuid_t));
36 if (!uuidp)
37 return -EFAULT;
38
39 result = sprintf(buf, "%pUl\n", uuidp);
> 40 acpi_os_unmap_iomem(uuidp, sizeof(uuid_t));
41 return result;
42 }
43 static DEVICE_ATTR_RO(generation_id);
44
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Hi Or,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on char-misc/char-misc-testing]
[also build test ERROR on v4.16-rc2 next-20180223]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/Or-Idgar/drivers-virt-vm_gen_counter-initial-driver-implementation/20180224-112017
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:
# save the attached .config to linux build tree
make ARCH=i386
All errors (new ones prefixed by >>):
>> ERROR: "hypervisor_kobj" [drivers/misc/vmgenid.ko] undefined!
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation