Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4640987imm; Tue, 9 Oct 2018 02:57:02 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Wj7KlqDoDHcA2uCW1Acmfg1T2spF312fS/Vd8dWb5mhQ7/IJ0CSiquv+/p61Bvr/xuMtc X-Received: by 2002:a63:5816:: with SMTP id m22-v6mr24505019pgb.332.1539079022427; Tue, 09 Oct 2018 02:57:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539079022; cv=none; d=google.com; s=arc-20160816; b=xcAxbM2VX3evcbVWjbG+tjKU5U388mWlUwseaCNGZy4Q6eK1275jQFcVUnCoLvn9bl RMVq+WgLbRhfYt7kX9AfqSqJY4dVqYRYR8+AmtwriImBn4wh/fRIz9wzhZ1lmGxE+Im1 mXeyW6kPeURdY97e6q27WS0cGt6K4rmXmZ+lt82cpKC3W4eujPE/qScFSPqkuh1mE6o7 upqQK7ERI0dR7+l9bUdemR6rf75VZYYyQ+LzuMU565VVu9MQ6IT8Tj6XXoFTS4yONkZu BzdT8E4xbQjcVFulIXbfntmlZhIZsT85HKDCde9hB28eQozd3EL49XiXy7UiZbsP2557 wJAQ== 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:to:from :dkim-signature; bh=/VM79TH2d1xRAK/Qy55i0mWq2AP3IAcNW47FMTpi/Hs=; b=wjgWg7cdqK41YBptA/ymgigFxVr/NbRX0oeQeaDsLXJ5PehGzJU6WA/LAWzpk8GBJB BJPVUGbEYva+XXfgkilbM3ROtsKEtvWWd1MWV1oy5ea3IDF2olvX7vkfLiZ9OMaLeWI4 L8eKcW+kXdRtHZfBw9KbVxrIk/7ZqJF8F50mrWsyqPAo0iBsQaYWt0A4U+YqhQ0ffoUe c3fZHzM/r/dnHfRyj/O9jF7cCvgIXiLbtspouwJNfPrb6eJkgwC00EzQbt5cNdbz/y2b yCNeqiAH40DjONiU2q9oqS9gUuxD4AxW+NMGGmPAn1NykXuauxMrUUHztDznlOL8O00v S1rA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=o1RXR+Qn; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n135-v6si23433562pfd.38.2018.10.09.02.56.47; Tue, 09 Oct 2018 02:57:02 -0700 (PDT) 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=@amazon.de header.s=amazon201209 header.b=o1RXR+Qn; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amazon.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726663AbeJIRLH (ORCPT + 99 others); Tue, 9 Oct 2018 13:11:07 -0400 Received: from smtp-fw-9102.amazon.com ([207.171.184.29]:21023 "EHLO smtp-fw-9102.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725823AbeJIRLG (ORCPT ); Tue, 9 Oct 2018 13:11:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1539078900; x=1570614900; h=from:to:subject:date:message-id; bh=/VM79TH2d1xRAK/Qy55i0mWq2AP3IAcNW47FMTpi/Hs=; b=o1RXR+QnP9PgOKHCOQtkLnKvXZ2GHptzsRRMa5TMmm6WaDkdcyc37ogt 5o7QZQduLhL4J40MMS80Q8uYL6ttS0qApaaXQoAW4GDKMTpi24rwdJGof XIPu17umefZUzQoqs0LFXkK2c+E5ddsgTS/7UZFyBUgx0X2Y7bVrzcTn+ Q=; X-IronPort-AV: E=Sophos;i="5.54,360,1534809600"; d="scan'208";a="635114436" Received: from sea3-co-svc-lb6-vlan3.sea.amazon.com (HELO email-inbound-relay-2c-397e131e.us-west-2.amazon.com) ([10.47.22.38]) by smtp-border-fw-out-9102.sea19.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 09 Oct 2018 09:54:57 +0000 Received: from uf8b156e456a5587c9af4.ant.amazon.com (pdx2-ws-svc-lb17-vlan2.amazon.com [10.247.140.66]) by email-inbound-relay-2c-397e131e.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id w999ssJb043783 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 9 Oct 2018 09:54:55 GMT Received: from uf8b156e456a5587c9af4.ant.amazon.com (localhost [127.0.0.1]) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Debian-3) with ESMTP id w999srEr004486; Tue, 9 Oct 2018 11:54:53 +0200 Received: (from sironi@localhost) by uf8b156e456a5587c9af4.ant.amazon.com (8.15.2/8.15.2/Submit) id w999sr3P004483; Tue, 9 Oct 2018 11:54:53 +0200 From: Filippo Sironi To: sironi@amazon.de, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] KVM: Start populating /sys/hypervisor with KVM entries Date: Tue, 9 Oct 2018 11:54:39 +0200 Message-Id: <1539078879-4372-1-git-send-email-sironi@amazon.de> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Start populating /sys/hypervisor with KVM entries when we're running on KVM. This is to replicate functionality that's available when we're running on Xen. Let's start with /sys/hypervisor/uuid, which users prefer over /sys/devices/virtual/dmi/id/product_uuid as a way to recognize a virtual machine, since it's also available when running on Xen HVM and on Xen PV and, on top of that doesn't require root privileges by default. Signed-off-by: Filippo Sironi --- drivers/Kconfig | 2 ++ drivers/Makefile | 2 ++ drivers/kvm/Kconfig | 14 ++++++++++++++ drivers/kvm/Makefile | 1 + drivers/kvm/sys-hypervisor.c | 26 ++++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 drivers/kvm/Kconfig create mode 100644 drivers/kvm/Makefile create mode 100644 drivers/kvm/sys-hypervisor.c diff --git a/drivers/Kconfig b/drivers/Kconfig index afc942c54814..597519c5f7c8 100644 --- a/drivers/Kconfig +++ b/drivers/Kconfig @@ -135,6 +135,8 @@ source "drivers/hv/Kconfig" source "drivers/xen/Kconfig" +source "drivers/kvm/Kconfig" + source "drivers/staging/Kconfig" source "drivers/platform/Kconfig" diff --git a/drivers/Makefile b/drivers/Makefile index 1056f9699192..727205e287fc 100644 --- a/drivers/Makefile +++ b/drivers/Makefile @@ -47,6 +47,8 @@ obj-y += soc/ obj-$(CONFIG_VIRTIO) += virtio/ obj-$(CONFIG_XEN) += xen/ +obj-$(CONFIG_KVM_GUEST) += kvm/ + # regulators early, since some subsystems rely on them to initialize obj-$(CONFIG_REGULATOR) += regulator/ diff --git a/drivers/kvm/Kconfig b/drivers/kvm/Kconfig new file mode 100644 index 000000000000..3fc041df7c11 --- /dev/null +++ b/drivers/kvm/Kconfig @@ -0,0 +1,14 @@ +menu "KVM driver support" + depends on KVM_GUEST + +config KVM_SYS_HYPERVISOR + bool "Create KVM entries under /sys/hypervisor" + depends on SYSFS + select SYS_HYPERVISOR + default y + help + Create KVM entries under /sys/hypervisor (e.g., uuid). When running + native or on another hypervisor, /sys/hypervisor may still be + present, but it will have no KVM entries. + +endmenu diff --git a/drivers/kvm/Makefile b/drivers/kvm/Makefile new file mode 100644 index 000000000000..73a43fc994b9 --- /dev/null +++ b/drivers/kvm/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_KVM_SYS_HYPERVISOR) += sys-hypervisor.o diff --git a/drivers/kvm/sys-hypervisor.c b/drivers/kvm/sys-hypervisor.c new file mode 100644 index 000000000000..ef04ca65cf1a --- /dev/null +++ b/drivers/kvm/sys-hypervisor.c @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#include + +#include +#include +#include + +static ssize_t uuid_show(struct kobject *obj, + struct kobj_attribute *attr, + char *buf) +{ + const char *uuid = dmi_get_system_info(DMI_PRODUCT_UUID); + return sprintf(buf, "%s\n", uuid); +} + +static struct kobj_attribute uuid = __ATTR_RO(uuid); + +static int __init uuid_init(void) +{ + if (!kvm_para_available()) + return 0; + return sysfs_create_file(hypervisor_kobj, &uuid.attr); +} + +device_initcall(uuid_init); -- 2.7.4