Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6856346yba; Tue, 14 May 2019 15:11:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjQ2SxMXpVORCIILBgwyaFCfGofJLXBdzSdqY+bQnuTOOFtfRURpseAG7/7SP9dCERPfk2 X-Received: by 2002:a17:902:7b8f:: with SMTP id w15mr40159366pll.314.1557871860686; Tue, 14 May 2019 15:11:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557871860; cv=none; d=google.com; s=arc-20160816; b=yj3ISY6135f0kM50vjXq+z0ue5WFHckg0OJaY0rM22IIaOG0NRAYE53VNoSfhb/8ru z7652C37kVqqRpj6bXvqbu8cDoSs/XAy5Do4aHR204fvW5QxO3O30IpLLz1HJEhZEtIk HAOArvPJKh7rVXAskQRSlhk7UUcjv5XEBtWVG6MPjCPj8r/01syserMKZXpG7NIK13T6 C5YLwf714gsiakwTKjTgZ/CkYHU/Ok9710T6Q6PEkjndmRvZuULeLoawtdkFYXCREpDk lz1FoRE+Al8cqtQ8kFXPQrzG6XuSI443+sqDhKKPB4Z0QlkMRBEXT6ieVZ6dT2aJqgOC lnmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature; bh=PRP1xBxuo+1R+ttuKDucVSYxEcz5wPNDFETPGhUhDeg=; b=bCUISpIKE2zYxgDPlvmuPwzt8BDFOqxxu3kDFqdejVWzOL5+f8zkWYH5PXcNBzXQRs 92uJ0eJ+E5kLtsD0rkNyilTfFit8LDpmkzolOL4Vwtl/HjbMIXFKANQRhzv/4WgVgz92 QYuAnbHU2Ld4cRhzVque9OZnNaT0I3G86RL/ldIdU7OBCF73F/bBNwh79DNQRYbuevSs oYlUeManO1+C+MIZ4tCqnC+AAFxnkpv8mIu0aa1uSJdPcIuVAkSPBdDzQ0udZXgVa/9J oBZcjZKl00LyaiJS4RpUCU4mZFRHDIk8FK0A1QlRQYfePWVqla+LrbhBStTEQynJjP+I QO6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazon.de header.s=amazon201209 header.b=LQpxGUSj; 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 m2si53734pgp.463.2019.05.14.15.10.44; Tue, 14 May 2019 15:11:00 -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=LQpxGUSj; 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 S1726379AbfENWIX (ORCPT + 99 others); Tue, 14 May 2019 18:08:23 -0400 Received: from smtp-fw-33001.amazon.com ([207.171.190.10]:1820 "EHLO smtp-fw-33001.amazon.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726148AbfENWIX (ORCPT ); Tue, 14 May 2019 18:08:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazon201209; t=1557871701; x=1589407701; h=from:to:cc:subject:date:message-id:references: in-reply-to:content-id:mime-version: content-transfer-encoding; bh=PRP1xBxuo+1R+ttuKDucVSYxEcz5wPNDFETPGhUhDeg=; b=LQpxGUSjdqJ5oZqjmFwOyytXC4+uIG9f5CzhSyAIs4n5Qe+yj3ax9Ezg Le2QvlX0VFHhOxfUnje/TWMZPxbI3ZfKd3aEhktB6C2wG6iUavTTopuxZ Ikad/aZyrzO8ZgIGa4RXSTcKUUqyVrZsTn9AxNttvf2QTgyraqEinZhJe U=; X-IronPort-AV: E=Sophos;i="5.60,470,1549929600"; d="scan'208";a="799668867" Received: from sea3-co-svc-lb6-vlan2.sea.amazon.com (HELO email-inbound-relay-2b-55156cd4.us-west-2.amazon.com) ([10.47.22.34]) by smtp-border-fw-out-33001.sea14.amazon.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 14 May 2019 22:08:19 +0000 Received: from EX13MTAUEA001.ant.amazon.com (pdx1-ws-svc-p6-lb9-vlan3.pdx.amazon.com [10.236.137.198]) by email-inbound-relay-2b-55156cd4.us-west-2.amazon.com (8.14.7/8.14.7) with ESMTP id x4EM8F2O129758 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=FAIL); Tue, 14 May 2019 22:08:19 GMT Received: from EX13D02EUC003.ant.amazon.com (10.43.164.10) by EX13MTAUEA001.ant.amazon.com (10.43.61.82) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 14 May 2019 22:08:18 +0000 Received: from EX13D02EUC001.ant.amazon.com (10.43.164.92) by EX13D02EUC003.ant.amazon.com (10.43.164.10) with Microsoft SMTP Server (TLS) id 15.0.1367.3; Tue, 14 May 2019 22:08:17 +0000 Received: from EX13D02EUC001.ant.amazon.com ([10.43.164.92]) by EX13D02EUC001.ant.amazon.com ([10.43.164.92]) with mapi id 15.00.1367.000; Tue, 14 May 2019 22:08:17 +0000 From: "Sironi, Filippo" To: Christian Borntraeger CC: LKML , KVM list , "boris.ostrovsky@oracle.com" , "cohuck@redhat.com" , "konrad.wilk@oracle.com" , "xen-devel@lists.xenproject.org" , "vasu.srinivasan@oracle.com" Subject: Re: [PATCH v2 1/2] KVM: Start populating /sys/hypervisor with KVM entries Thread-Topic: [PATCH v2 1/2] KVM: Start populating /sys/hypervisor with KVM entries Thread-Index: AQHVCmguTMwTmVyYP0+tMrT8Z/dQMaZqvgUAgAAL5ICAAGRWAA== Date: Tue, 14 May 2019 22:08:16 +0000 Message-ID: <0E82B8C2-5169-4788-B1C0-1668D1F74204@amazon.de> References: <1539078879-4372-1-git-send-email-sironi@amazon.de> <1557847002-23519-1-git-send-email-sironi@amazon.de> <1557847002-23519-2-git-send-email-sironi@amazon.de> <56DAB9BD-2543-49DA-9886-C9C8F2B814F9@amazon.de> In-Reply-To: <56DAB9BD-2543-49DA-9886-C9C8F2B814F9@amazon.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.43.166.102] Content-Type: text/plain; charset="us-ascii" Content-ID: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On 14. May 2019, at 18:09, Sironi, Filippo wrote: > = >> On 14. May 2019, at 17:26, Christian Borntraeger wrote: >> = >>> On 14.05.19 17:16, Filippo Sironi wrote: >>> 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. >>> = >>> 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. >>> Let's create arch-specific hooks so that different architectures can >>> provide different implementations. >>> = >>> Signed-off-by: Filippo Sironi >>> --- >>> v2: >>> * move the retrieval of the VM UUID out of uuid_show and into >>> kvm_para_get_uuid, which is a weak function that can be overwritten >>> = >>> drivers/Kconfig | 2 ++ >>> drivers/Makefile | 2 ++ >>> drivers/kvm/Kconfig | 14 ++++++++++++++ >>> drivers/kvm/Makefile | 1 + >>> drivers/kvm/sys-hypervisor.c | 30 ++++++++++++++++++++++++++++++ >>> 5 files changed, 49 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 45f9decb9848..90eb835fe951 100644 >>> --- a/drivers/Kconfig >>> +++ b/drivers/Kconfig >>> @@ -146,6 +146,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 c61cde554340..79cc92a3f6bf 100644 >>> --- a/drivers/Makefile >>> +++ b/drivers/Makefile >>> @@ -44,6 +44,8 @@ obj-y +=3D soc/ >>> obj-$(CONFIG_VIRTIO) +=3D virtio/ >>> obj-$(CONFIG_XEN) +=3D xen/ >>> = >>> +obj-$(CONFIG_KVM_GUEST) +=3D kvm/ >>> + >>> # regulators early, since some subsystems rely on them to initialize >>> obj-$(CONFIG_REGULATOR) +=3D 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) +=3D sys-hypervisor.o >>> diff --git a/drivers/kvm/sys-hypervisor.c b/drivers/kvm/sys-hypervisor.c >>> new file mode 100644 >>> index 000000000000..43b1d1a09807 >>> --- /dev/null >>> +++ b/drivers/kvm/sys-hypervisor.c >>> @@ -0,0 +1,30 @@ >>> +/* SPDX-License-Identifier: GPL-2.0 */ >>> + >>> +#include >>> + >>> +#include >>> +#include >>> + >>> +__weak const char *kvm_para_get_uuid(void) >>> +{ >>> + return NULL; >>> +} >>> + >>> +static ssize_t uuid_show(struct kobject *obj, >>> + struct kobj_attribute *attr, >>> + char *buf) >>> +{ >>> + const char *uuid =3D kvm_para_get_uuid(); >> = >> I would prefer to have kvm_para_get_uuid return a uuid_t >> but char * will probably work out as well. > = > Let me give this a quick spin. I looked into getting a uuid_t. At least for architectures where we retrieve that bit of information from DMI tables, this is undesirable since the interpretation of the UUID changed with DMI 2.6 (the first 3 fields are now encoded in little-endian). This means that we wouldn't know how to print it in this generic code. I think that it's best if the architecture specific code turns the UUID into the string representation. >>> + return sprintf(buf, "%s\n", uuid); >>> +} >>> + >>> +static struct kobj_attribute uuid =3D __ATTR_RO(uuid); >>> + >>> +static int __init uuid_init(void) >>> +{ >>> + if (!kvm_para_available()) >> = >> Isnt kvm_para_available a function that is defined in the context of the= HOST >> and not of the guest? > = > No, kvm_para_available is defined in the guest context. > On x86, it checks for the presence of the KVM CPUID leafs. > = >>> + return 0; >>> + return sysfs_create_file(hypervisor_kobj, &uuid.attr); >>> +} >>> + >>> +device_initcall(uuid_init); Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich Ust-ID: DE 289 237 879 Eingetragen am Amtsgericht Charlottenburg HRB 149173 B