Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4980688imm; Tue, 9 Oct 2018 08:01:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV63p7bKJel/gVQpMzoZzUNmsCpFh7c4wYlcF/qxpHo3p9rXI7tQ+sXfSSm2ABgb+HE61WOT0 X-Received: by 2002:a63:d048:: with SMTP id s8-v6mr25641628pgi.311.1539097319361; Tue, 09 Oct 2018 08:01:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539097319; cv=none; d=google.com; s=arc-20160816; b=qRETgUxQjzWWayVymtcrbgwACfENUfto7b5RO4KDsNrcF5hIAEphSSAoeB+0shnlBA QPntFWpDCDGDqpv/P/v36mG6sR3SMLyU1/PPcQjf+LpM/0Qhd0cH4LLP9Wiorh2D0syt VAHJw7NK6v4zC9F2wQQDMcU1uQg99jsTsw1srq1NUogM6dPSAWch/e7pjXvcTzcX5wq9 GzC9/IdRf1CH0jT9Ue5uU4softzdPHzMMMvRE5gpo2C3+U2ulsveravP21s+weoMtF1G eg8LEBaTsH71BbSBZMeIH6AMwoNXScEoX6EGE0ob32VF/FrQURMkHG/8sqLuokcYDD3X uAKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=hzFePnuqT7p71/Pq56u2NqOhrWhI/Dvfknmvt3Q5hw8=; b=sy5Svw6l+X9VWUXcTsI/4hJmb1Ilm6mGHm4SLZlr894+Owgd2DWTSP4xri6lR10Wih qv71zFLJh+eAyBLJlWJ05ZeDzXiP2RR7fchhmSfMQbH817D7L6yAgi/eB4Y1HAcO3dve Gqc0hwCmY2ceexCNvq/7noj5BtOA35i5b2utZj8sZVZoPffZCictD8OxKcHFPViDb43a 2nL8GtXgSdcRMo7qNUmGPuMFXnzdwlaf9cJYdvStczb/fLxbgKXcYRXDUUxa/1ju3wk4 WJ1WHeKpk7hF2r8RAKSnvTCiw12aBoCZpVjyFAoe6ays+uKbynfBwgqr6IWrJA++d/kU 8/zA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=ZsTzpb07; 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=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y92-v6si22503889plb.177.2018.10.09.08.01.40; Tue, 09 Oct 2018 08:01:59 -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=@oracle.com header.s=corp-2018-07-02 header.b=ZsTzpb07; 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=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727152AbeJIWSA (ORCPT + 99 others); Tue, 9 Oct 2018 18:18:00 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:46160 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726563AbeJIWSA (ORCPT ); Tue, 9 Oct 2018 18:18:00 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w99EwbCE038569; Tue, 9 Oct 2018 15:00:38 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : references : mime-version : content-type : in-reply-to; s=corp-2018-07-02; bh=hzFePnuqT7p71/Pq56u2NqOhrWhI/Dvfknmvt3Q5hw8=; b=ZsTzpb071gAnsooaOiO4iimF558LOmIAszjIYGvG5syTg2OpNv0onWJ3JPWC62w3bEGT 1BdoQMUnfbuV7cxGDQpnAODmiSgKow9Ohl7ulM1VvhYPgrlSgVtxAFRCHGm4ujEJaXxi oWsVoFdBk43prYan+2tExwYheu9yQeP4pfUt3g7o0Y1u/yBnm8Aq4Xhk2jcqekdfl9q4 QlphkyMpiArDG1XBjzX4LmHsenz0xBHAxBN62osKarNNOaw6lCdiOoJ7lEnseGR66T50 nxkqIbh6msoTcsyQGlovGxUidxDjUNVLEP2dlsni/MEf2EL3zZpb4ntyF8GvlGDKKGcK AQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2mxn0pwxsg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 09 Oct 2018 15:00:38 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w99F0bQ1015092 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 9 Oct 2018 15:00:37 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w99F0aED012578; Tue, 9 Oct 2018 15:00:36 GMT Received: from char.us.oracle.com (/10.152.32.25) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 09 Oct 2018 15:00:36 +0000 Received: by char.us.oracle.com (Postfix, from userid 1000) id 711F86A013A; Tue, 9 Oct 2018 11:00:35 -0400 (EDT) Date: Tue, 9 Oct 2018 11:00:35 -0400 From: Konrad Rzeszutek Wilk To: Filippo Sironi Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: Re: [PATCH] KVM: Start populating /sys/hypervisor with KVM entries Message-ID: <20181009150035.GK5106@char.us.oracle.com> References: <1539078879-4372-1-git-send-email-sironi@amazon.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1539078879-4372-1-git-send-email-sironi@amazon.de> User-Agent: Mutt/1.8.3 (2017-05-23) X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9040 signatures=668706 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810090147 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 09, 2018 at 11:54:39AM +0200, 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. > > 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. Yeey! Thank you for doing this. It has been on my TODO but just never got to it. I think you also need to update the Documentation/../sysfs file. > > 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 >