Received: by 10.223.185.116 with SMTP id b49csp7489308wrg; Thu, 1 Mar 2018 06:24:28 -0800 (PST) X-Google-Smtp-Source: AG47ELuzcDTxEruFWie9Y9/AWLcc0qDqJYjEo0Mwkb1Ir2UWXYrlFrG005ZWsx0oytOySJwO5YG9 X-Received: by 10.101.92.72 with SMTP id v8mr1675606pgr.153.1519914268166; Thu, 01 Mar 2018 06:24:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519914268; cv=none; d=google.com; s=arc-20160816; b=QnK1AJwZKBNOoA2tpicSm8g/fNniq6phdjno1huRvDnbq/n83PZxaqaZWGfxbx/w2Q XBMCKlwe09IRo8hdzyWJik62ZhpBUJEZDyqTxxSjdpzruPVLFRbfGOJ2AYjzpKpwZ6d6 RVx8aPGzIktM/lc8+e2UrJBNYuNFa4MZ5YoxnLe8XjDwuSwxZPn7JuPJ8xa/0O2P6mT3 WtQVgMG7Bu2N4ea8Ixr5w1LDJfva7VnszzrxABohYZHaEskB3elm3A15EnAz2AGP//Yb YLrntPPASC0bK8hDrCXXNqa4COZkhgzzW55swbiisRdK9i2vjZdPxVH8VqpefT+1pu0a UT7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=k/HOeSC97e7TAVoeRcqMlAAZhoMC090TKeuK3laTsWo=; b=mdx0itRZpyi4RCL1qccuw5vofiyj7EOrnEAMgjkcrxf0gMekJA9ntqo2UCZuwun23y P1N201fmK1lzWFiLWgwGs//3RHxqGHCdjMIXhzxXPB3PsqBpLSG7fVGd1avfi3Z2l7Z+ jEu0A3u0oy6Dbiue748WOrqq21a1/ORDwT74EteBqz64G+oQycxUDcilFvN8jDo2k+gG 1lWK/JZAsIn0YQN6a3ncD7VaDu1UrIw9p6W7RaKyHn0lT7ypBN48j+Akq7zkYYYyE0pK iOmpeC07LzH7h8VhfzSfnezR/nrwFdwL26Wga798z2GQxX5aoCzUZXNarhsEQ3VEd/3X BbLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtualoco.com header.s=it header.b=GEHkzIBJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k9si2538660pgo.42.2018.03.01.06.24.12; Thu, 01 Mar 2018 06:24:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@virtualoco.com header.s=it header.b=GEHkzIBJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1031461AbeCAOWl (ORCPT + 99 others); Thu, 1 Mar 2018 09:22:41 -0500 Received: from sender-of-o52.zoho.com ([135.84.80.217]:21475 "EHLO sender-of-o52.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1031437AbeCAOWh (ORCPT ); Thu, 1 Mar 2018 09:22:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1519914152; s=it; d=virtualoco.com; i=idgar@virtualoco.com; h=From:To:Cc:Subject:Date:Message-Id; l=6230; bh=k/HOeSC97e7TAVoeRcqMlAAZhoMC090TKeuK3laTsWo=; b=GEHkzIBJjrJoRu9Bx/Hh26uddOW5tddcOiLgQCVNjf6QFsDoc8exrP1VIV3TxCDz WqMvIg2/K4EZ7AEEWWdENJICZQKmSl8+mjgOVTeF/rh/z+tSWndeLwbiLbNCMvtxiRO 9x3b88Lt6yPxTIHNcmOYrYC6t+fR2kNfkphKKHZE= Received: from ibm-p8-kvm-03-guest-02.virt.pnr.lab.eng.rdu2.redhat.com (bzq-82-81-161-50.red.bezeqint.net [82.81.161.50]) by mx.zohomail.com with SMTPS id 1519914152345187.86853199119446; Thu, 1 Mar 2018 06:22:32 -0800 (PST) From: Or Idgar To: linux-kernel@vger.kernel.org, arnd@arndb.de, gregkh@linuxfoundation.org Cc: oidgar@redhat.com, idgar@virtualoco.com, ghammer@redhat.com, Or Idgar Subject: [PATCH v5] drivers/misc: vm_gen_counter: initial driver implementation Date: Thu, 1 Mar 2018 16:22:15 +0200 Message-Id: <20180301142215.11812-1-idgar@virtualoco.com> X-Mailer: git-send-email 2.14.3 X-ZohoMailClient: External X-ZohoMail: Z_638866495 SPT_1 Z_638866494 SPT_1 SLF_D Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Or Idgar 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 --- Changes in v5: - added to VMGENID module dependency on ACPI module. Documentation/ABI/testing/sysfs-hypervisor | 13 +++ drivers/misc/Kconfig | 7 ++ drivers/misc/Makefile | 1 + drivers/misc/vmgenid.c | 142 +++++++++++++++++++++++++++++ 4 files changed, 163 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 + Gal Hammer +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..a39feff6a867 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -500,6 +500,13 @@ config MISC_RTSX tristate default MISC_RTSX_PCI || MISC_RTSX_USB +config VMGENID + depends on ACPI + 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..6c8d8fe75335 --- /dev/null +++ b/drivers/misc/vmgenid.c @@ -0,0 +1,142 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Virtual Machine Generation ID driver + * + * Copyright (C) 2018 Red Hat, Inc. All rights reserved. + * Authors: + * Or Idgar + * Gal Hammer + * + */ +#include +#include +#include +#include +#include +#include + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Or Idgar "); +MODULE_AUTHOR("Gal Hammer "); +MODULE_DESCRIPTION("Virtual Machine Generation ID"); +MODULE_VERSION("0.1"); + +ACPI_MODULE_NAME("vmgenid"); + +static u64 phys_addr; + +static ssize_t generation_id_show(struct device *_d, + struct device_attribute *attr, char *buf) +{ + void __iomem *uuid_map; + uuid_t uuid; + ssize_t result; + + uuid_map = acpi_os_map_iomem(phys_addr, sizeof(uuid_t)); + if (!uuid_map) + return -EFAULT; + + memcpy_fromio(&uuid, uuid_map, sizeof(uuid_t)); + result = sprintf(buf, "%pUl\n", &uuid); + acpi_os_unmap_iomem(uuid_map, 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) +{ + void __iomem *uuid_map; + + uuid_map = acpi_os_map_iomem(phys_addr, sizeof(uuid_t)); + if (!uuid_map) + return -EFAULT; + memcpy_fromio(buf, uuid_map, sizeof(uuid_t)); + acpi_os_unmap_iomem(uuid_map, 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; + + phys_addr = 0; + for (i = 0; i < pss->package.count; i++) { + element = &(pss->package.elements[i]); + if (element->type != ACPI_TYPE_INTEGER) + return -EFAULT; + phys_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