From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12BD5C64EAD for ; Tue, 9 Oct 2018 09:55:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C110821479 for ; Tue, 9 Oct 2018 09:55:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=amazon.de header.i=@amazon.de header.b="o1RXR+Qn" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C110821479 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=amazon.de Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726668AbeJIRLH (ORCPT ); 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