From: "Sironi, Filippo" <sironi@amazon.de>
To: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: KVM list <kvm@vger.kernel.org>,
"konrad.wilk@oracle.com" <konrad.wilk@oracle.com>,
"cohuck@redhat.com" <cohuck@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
"boris.ostrovsky@oracle.com" <boris.ostrovsky@oracle.com>,
"vasu.srinivasan@oracle.com" <vasu.srinivasan@oracle.com>
Subject: Re: [Xen-devel] [PATCH v2 1/2] KVM: Start populating /sys/hypervisor with KVM entries
Date: Tue, 14 May 2019 22:08:16 +0000 [thread overview]
Message-ID: <0E82B8C2-5169-4788-B1C0-1668D1F74204@amazon.de> (raw)
In-Reply-To: <56DAB9BD-2543-49DA-9886-C9C8F2B814F9@amazon.de>
> On 14. May 2019, at 18:09, Sironi, Filippo <sironi@amazon.de> wrote:
>
>> On 14. May 2019, at 17:26, Christian Borntraeger <borntraeger@de.ibm.com> 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 <sironi@amazon.de>
>>> ---
>>> 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 += 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..43b1d1a09807
>>> --- /dev/null
>>> +++ b/drivers/kvm/sys-hypervisor.c
>>> @@ -0,0 +1,30 @@
>>> +/* SPDX-License-Identifier: GPL-2.0 */
>>> +
>>> +#include <asm/kvm_para.h>
>>> +
>>> +#include <linux/kobject.h>
>>> +#include <linux/sysfs.h>
>>> +
>>> +__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 = 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 = __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
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2019-05-14 22:08 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1539078879-4372-1-git-send-email-sironi@amazon.de>
[not found] ` <c81b65ba-c562-1869-483b-aee5229501e0@de.ibm.com>
2018-10-09 16:21 ` [PATCH] KVM: Start populating /sys/hypervisor with KVM entries Boris Ostrovsky
[not found] ` <61740f41-c7e3-edaf-68ac-2e4c4a99523b@oracle.com>
2018-10-09 17:50 ` Cornelia Huck
2019-05-14 15:16 ` [Xen-devel] " Filippo Sironi
2019-05-14 15:16 ` [Xen-devel] [PATCH v2 1/2] " Filippo Sironi
2019-05-14 15:26 ` Christian Borntraeger
2019-05-14 16:09 ` Sironi, Filippo
2019-05-14 16:09 ` [Xen-devel] " Sironi, Filippo
2019-05-14 16:31 ` Christian Borntraeger
2019-05-14 16:31 ` [Xen-devel] " Christian Borntraeger
2019-05-14 22:08 ` Sironi, Filippo
2019-05-14 22:08 ` Sironi, Filippo [this message]
2019-05-14 15:26 ` Christian Borntraeger
2019-05-16 13:50 ` [Xen-devel] " Alexander Graf
2019-05-16 14:02 ` Andrew Cooper
2019-05-16 14:02 ` [Xen-devel] " Andrew Cooper
2019-05-16 14:08 ` Alexander Graf
2019-05-16 14:08 ` [Xen-devel] " Alexander Graf
2019-05-16 15:02 ` Boris Ostrovsky
2019-05-16 15:14 ` Sironi, Filippo
2019-05-16 15:14 ` [Xen-devel] " Sironi, Filippo
2019-05-16 15:02 ` Boris Ostrovsky
2019-05-17 15:41 ` [Xen-devel] " Sironi, Filippo
2019-05-31 9:06 ` Alexander Graf
2019-05-31 9:12 ` Raslan, KarimAllah
2019-05-31 9:26 ` Alexander Graf
2019-05-31 9:26 ` Alexander Graf
2019-05-31 9:38 ` [Xen-devel] " Marc Zyngier
2019-05-31 9:38 ` Marc Zyngier
2019-05-31 9:12 ` Raslan, KarimAllah
2019-05-31 9:06 ` Alexander Graf
2019-05-17 15:41 ` Sironi, Filippo
2019-05-16 13:50 ` Alexander Graf
2019-05-14 15:16 ` Filippo Sironi
2019-05-14 15:16 ` [Xen-devel] [PATCH v2 2/2] KVM: x86: Implement the arch-specific hook to report the VM UUID Filippo Sironi
2019-05-16 13:56 ` Alexander Graf
2019-05-16 15:25 ` Sironi, Filippo
2019-05-16 15:33 ` Alexander Graf
2019-05-16 16:40 ` Boris Ostrovsky
2019-05-16 17:41 ` Sironi, Filippo
2019-05-16 17:49 ` Alexander Graf
2019-05-16 17:49 ` Alexander Graf
2019-05-16 17:41 ` Sironi, Filippo
2019-05-16 16:40 ` Boris Ostrovsky
2019-05-16 15:33 ` Alexander Graf
2019-05-16 15:25 ` Sironi, Filippo
2019-05-16 13:56 ` Alexander Graf
2019-05-14 15:16 ` Filippo Sironi
2019-05-14 15:16 ` KVM: Start populating /sys/hypervisor with KVM entries Filippo Sironi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0E82B8C2-5169-4788-B1C0-1668D1F74204@amazon.de \
--to=sironi@amazon.de \
--cc=boris.ostrovsky@oracle.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=konrad.wilk@oracle.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vasu.srinivasan@oracle.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).