From: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
To: Elliot Berman <quic_eberman@quicinc.com>,
Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Murali Nalajala <quic_mnalajal@quicinc.com>,
Trilok Soni <quic_tsoni@quicinc.com>,
Srivatsa Vaddagiri <quic_svaddagi@quicinc.com>,
Carl van Schaik <quic_cvanscha@quicinc.com>,
Andy Gross <agross@kernel.org>,
linux-arm-kernel@lists.infradead.org,
Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>,
Sudeep Holla <sudeep.holla@arm.com>,
Marc Zyngier <maz@kernel.org>, Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Jonathan Corbet <corbet@lwn.net>, Will Deacon <will@kernel.org>,
Catalin Marinas <catalin.marinas@arm.com>,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v2 05/11] virt: gunyah: Add sysfs nodes
Date: Tue, 2 Aug 2022 10:42:54 +0300 [thread overview]
Message-ID: <5f22bf9c-3694-0f08-d472-a3c952c081e7@linaro.org> (raw)
In-Reply-To: <20220801211240.597859-6-quic_eberman@quicinc.com>
On 02/08/2022 00:12, Elliot Berman wrote:
> Add /sys/hypervisor support when detecting that Linux is running in a
> Gunyah environment. Export the version of Gunyah which is reported via
> the hyp_identify hypercall.
>
> Signed-off-by: Elliot Berman <quic_eberman@quicinc.com>
> ---
> .../ABI/testing/sysfs-hypervisor-gunyah | 37 +++++
> MAINTAINERS | 2 +
> arch/arm64/include/asm/gunyah.h | 4 +
> drivers/virt/Kconfig | 1 +
> drivers/virt/Makefile | 1 +
> drivers/virt/gunyah/Kconfig | 13 ++
> drivers/virt/gunyah/Makefile | 4 +
> drivers/virt/gunyah/sysfs.c | 139 ++++++++++++++++++
> 8 files changed, 201 insertions(+)
> create mode 100644 Documentation/ABI/testing/sysfs-hypervisor-gunyah
> create mode 100644 drivers/virt/gunyah/Kconfig
> create mode 100644 drivers/virt/gunyah/Makefile
> create mode 100644 drivers/virt/gunyah/sysfs.c
>
> diff --git a/Documentation/ABI/testing/sysfs-hypervisor-gunyah b/Documentation/ABI/testing/sysfs-hypervisor-gunyah
> new file mode 100644
> index 000000000000..41bce1965c91
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-hypervisor-gunyah
> @@ -0,0 +1,37 @@
> +What: /sys/hypervisor/type
These whole set of entries doesn't look right. You are defining
gunyah-specific entries in the generic /sys/hypervisor directory. Other
hypervisors will have their own set of ABI/sysfs files/etc/.
I would suggest using /sys/hypervisor/gunyah as a base dir. Then you can
define any gunyah-specific file in it without caring if it applies to
other hypervisors or not.
> +Date: August 2022
> +KernelVersion: 5.20
> +Contact: linux-arm-msm@vger.kernel.org
> +Description: If running under Gunyah:
> + Type of hypervisor:
> + "gunyah": Gunyah hypervisor
And this will be gone if you adopt /sys/hypervisor/gunyah approach
> +
> +What: /sys/hypervisor/features
> +Date: August 2022
> +KernelVersion: 5.20
> +Contact: linux-arm-msm@vger.kernel.org
> +Description: If running under Gunyah:
> + Space separated list of features supported by Linux and Gunyah:
> + "cspace": Gunyah devices
> + "doorbell": Sending/receiving virtual interrupts via Gunyah doorbells
> + "message-queue": Sending/receiving messages via Gunyah message queues
> + "vic": Interrupt lending
> + "vpm": Virtual platform management
> + "vcpu": Virtual CPU management
> + "memextent": Memory lending/management
> + "trace": Gunyah hypervisor tracing
> +
> +
> +What: /sys/hypervisor/version/api
> +Date: August 2022
> +KernelVersion: 5.20
> +Contact: linux-arm-msm@vger.kernel.org
> +Description: If running under Gunyah:
> + The Gunyah API version.
> +
> +What: /sys/hypervisor/version/variant
> +Date: August 2022
> +KernelVersion: 5.20
> +Contact: linux-arm-msm@vger.kernel.org
> +Description: If running under Gunyah:
> + The Gunyah variant (build) version.
If this is a build version, please call it a build version rather than
variant.
> \ No newline at end of file
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 2e4f1d9ed47b..e63c51ee1a2a 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -8741,9 +8741,11 @@ M: Elliot Berman <quic_eberman@quicinc.com>
> M: Murali Nalajala <quic_mnalajal@quicinc.com>
> L: linux-arm-msm@vger.kernel.org
> S: Maintained
> +F: Documentation/ABI/testing/sysfs-hypervisor-gunyah
> F: Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml
> F: Documentation/virt/gunyah/
> F: arch/arm64/include/asm/gunyah.h
> +F: drivers/virt/gunyah/
> F: include/linux/gunyah.h
>
> HABANALABS PCI DRIVER
> diff --git a/arch/arm64/include/asm/gunyah.h b/arch/arm64/include/asm/gunyah.h
> index 4820e9389f40..3aee35009910 100644
> --- a/arch/arm64/include/asm/gunyah.h
> +++ b/arch/arm64/include/asm/gunyah.h
> @@ -19,11 +19,15 @@
> (GH_CALL_TYPE_SERVICE << GH_CALL_TYPE_SHIFT) \
> | ((fn) & GH_CALL_FUNCTION_NUM_MASK))
>
> +#define GH_HYPERCALL_CALL_UID GH_SERVICE(0x3f01)
> +
> #define GH_HYPERCALL(fn) ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64, \
> ARM_SMCCC_OWNER_VENDOR_HYP, \
> (GH_CALL_TYPE_HYPERCALL << GH_CALL_TYPE_SHIFT) \
> | ((fn) & GH_CALL_FUNCTION_NUM_MASK))
>
> +#define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000)
> +
> #define ___gh_count_args(_0, _1, _2, _3, _4, _5, _6, _7, _8, x, ...) x
>
> #define __gh_count_args(...) \
> diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
> index 87ef258cec64..259dc2be6cad 100644
> --- a/drivers/virt/Kconfig
> +++ b/drivers/virt/Kconfig
> @@ -52,4 +52,5 @@ source "drivers/virt/coco/efi_secret/Kconfig"
>
> source "drivers/virt/coco/sev-guest/Kconfig"
>
> +source "drivers/virt/gunyah/Kconfig"
> endif
> diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile
> index 093674e05c40..ec4fdfa8eef1 100644
> --- a/drivers/virt/Makefile
> +++ b/drivers/virt/Makefile
> @@ -6,6 +6,7 @@
> obj-$(CONFIG_FSL_HV_MANAGER) += fsl_hypervisor.o
> obj-$(CONFIG_VMGENID) += vmgenid.o
> obj-y += vboxguest/
> +obj-$(CONFIG_GUNYAH) += gunyah/
>
> obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/
> obj-$(CONFIG_ACRN_HSM) += acrn/
> diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig
> new file mode 100644
> index 000000000000..1e493017885e
> --- /dev/null
> +++ b/drivers/virt/gunyah/Kconfig
> @@ -0,0 +1,13 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +config GUNYAH
> + tristate "Gunyah Virtualization drivers"
> + depends on ARM64
> + select SYS_HYPERVISOR
> + help
> + The Gunyah drivers are the helper interfaces that runs in a guest VM
> + such as basic inter-VM IPC and signaling mechanisms and higher level
> + services such as memory/device sharing, IRQ sharing, and so on.
> +
> + Say Y here to enable the drivers needed to interact in a Gunyah
> + virtual environment.
> diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile
> new file mode 100644
> index 000000000000..0aa086f9149f
> --- /dev/null
> +++ b/drivers/virt/gunyah/Makefile
> @@ -0,0 +1,4 @@
> +# SPDX-License-Identifier: GPL-2.0-only
> +
> +gunyah-y += sysfs.o
> +obj-$(CONFIG_GUNYAH) += gunyah.o
> \ No newline at end of file
> diff --git a/drivers/virt/gunyah/sysfs.c b/drivers/virt/gunyah/sysfs.c
> new file mode 100644
> index 000000000000..253433a939cf
> --- /dev/null
> +++ b/drivers/virt/gunyah/sysfs.c
> @@ -0,0 +1,139 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
> + */
> +
> +#define pr_fmt(fmt) "gunyah: " fmt
> +
> +#include <linux/kobject.h>
> +#include <linux/gunyah.h>
> +#include <linux/module.h>
> +#include <linux/printk.h>
> +#include <linux/init.h>
> +#include <linux/of.h>
> +
> +#define QC_HYP_UID0 0x19bd54bd
> +#define QC_HYP_UID1 0x0b37571b
> +#define QC_HYP_UID2 0x946f609b
> +#define QC_HYP_UID3 0x54539de6
> +
> +#define GUNYAH_UID0 0x673d5f14
> +#define GUNYAH_UID1 0x9265ce36
> +#define GUNYAH_UID2 0xa4535fdb
> +#define GUNYAH_UID3 0xc1d58fcd
> +
> +#define gh_uid_matches(prefix, uid) \
> + ((uid)[0] == prefix ## _UID0 && (uid)[1] == prefix ## _UID1 && \
> + (uid)[2] == prefix ## _UID2 && (uid)[3] == prefix ## _UID3)
> +
> +#define GH_API_INFO_API_VERSION(x) (((x) >> 0) & 0x3fff)
> +#define GH_API_INFO_BIG_ENDIAN(x) (((x) >> 14) & 1)
> +#define GH_API_INFO_IS_64BIT(x) (((x) >> 15) & 1)
> +#define GH_API_INFO_VARIANT(x) (((x) >> 56) & 0xff)
> +
> +#define GH_IDENTIFY_PARTITION_CSPACE(flags) (((flags)[0] >> 0) & 1)
> +#define GH_IDENTIFY_DOORBELL(flags) (((flags)[0] >> 1) & 1)
> +#define GH_IDENTIFY_MSGQUEUE(flags) (((flags)[0] >> 2) & 1)
> +#define GH_IDENTIFY_VIC(flags) (((flags)[0] >> 3) & 1)
> +#define GH_IDENTIFY_VPM(flags) (((flags)[0] >> 4) & 1)
> +#define GH_IDENTIFY_VCPU(flags) (((flags)[0] >> 5) & 1)
> +#define GH_IDENTIFY_MEMEXTENT(flags) (((flags)[0] >> 6) & 1)
> +#define GH_IDENTIFY_TRACE_CTRL(flags) (((flags)[0] >> 7) & 1)
> +
> +struct gh_hypercall_hyp_identify_resp {
> + u64 api_info;
> + u64 flags[3];
> +};
> +
> +static struct gh_hypercall_hyp_identify_resp gunyah_api;
> +
> +static ssize_t type_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
> +{
> + return sysfs_emit(buffer, "gunyah\n");
> +}
> +static struct kobj_attribute type_attr = __ATTR_RO(type);
> +
> +static ssize_t api_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
> +{
> + return sysfs_emit(buffer, "%d\n", (int)GH_API_INFO_API_VERSION(gunyah_api.api_info));
> +}
> +static struct kobj_attribute api_attr = __ATTR_RO(api);
> +
> +static ssize_t variant_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
> +{
> + return sysfs_emit(buffer, "%d\n", (int)GH_API_INFO_VARIANT(gunyah_api.api_info));
> +}
> +static struct kobj_attribute variant_attr = __ATTR_RO(variant);
> +
> +static ssize_t features_show(struct kobject *kobj, struct kobj_attribute *attr, char *buffer)
> +{
> + return sysfs_emit(buffer, "\n");
empty features? oook. At least it deserves a comment here, if you plan
to add features later in these series. But strictly speaking it might be
better to define the features ABI once you start populating it.
> +}
> +static struct kobj_attribute features_attr = __ATTR_RO(features);
> +
> +static struct attribute *version_attrs[] = {
> + &api_attr.attr,
> + &variant_attr.attr,
> + NULL
> +};
> +
> +static const struct attribute_group version_group = {
> + .name = "version",
> + .attrs = version_attrs,
> +};
> +
> +static int __init gh_sysfs_register(void)
> +{
> + int ret;
> +
> + ret = sysfs_create_file(hypervisor_kobj, &type_attr.attr);
> + if (ret)
> + return ret;
> +
> + ret = sysfs_create_group(hypervisor_kobj, &version_group);
> + if (ret)
> + return ret;
> +
> + return sysfs_create_file(hypervisor_kobj, &features_attr.attr);
error path?
> +}
> +
> +static void gh_sysfs_unregister(void)
> +{
> + sysfs_remove_file(hypervisor_kobj, &type_attr.attr);
> + sysfs_remove_group(hypervisor_kobj, &version_group);
Please unwind in a backwards manner. Also one sysfs_remove_ is missing.
> +}
> +
> +static int __init gunyah_init(void)
> +{
> + unsigned long uid[4];
> +
> + arch_gh_hypercall(GH_HYPERCALL_CALL_UID, 0, uid[0], uid[1], uid[2], uid[3]);
> +
> + if (!(gh_uid_matches(GUNYAH, uid) || gh_uid_matches(QC_HYP, uid)))
> + return 0;
if (!gh_uid_matched(GUNYAH, uid) &&
!gh_uid_matches(QC_HYP, uid))
return -ENODEV;
BTW: what is the difference between GUNYAH and QC_HYP here?
> +
> + arch_gh_hypercall(GH_HYPERCALL_HYP_IDENTIFY, 0, gunyah_api.api_info,
> + gunyah_api.flags[0], gunyah_api.flags[1], gunyah_api.flags[2]);
> +
> + if (GH_API_INFO_API_VERSION(gunyah_api.api_info) != 1) {
> + pr_warn("Unrecognized gunyah version: %llu. Currently supported: 1\n",
> + GH_API_INFO_API_VERSION(gunyah_api.api_info));
> + return 0;
> + }
> +
> + pr_notice("Running under Gunyah hypervisor v%lld/%llx\n",
> + GH_API_INFO_API_VERSION(gunyah_api.api_info),
> + GH_API_INFO_VARIANT(gunyah_api.api_info));
> +
> + return gh_sysfs_register();
> +}
> +module_init(gunyah_init);
> +
> +static void __exit gunyah_exit(void)
> +{
> + gh_sysfs_unregister();
> +}
> +module_exit(gunyah_exit);
> +
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("Gunyah Hypervisor Driver");
Sysfs driver?
--
With best wishes
Dmitry
next prev parent reply other threads:[~2022-08-02 7:43 UTC|newest]
Thread overview: 50+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-01 21:12 [PATCH v2 00/11] Drivers for gunyah hypervisor Elliot Berman
2022-08-01 21:12 ` [PATCH v2 01/11] docs: gunyah: Introduce Gunyah Hypervisor Elliot Berman
2022-08-01 21:29 ` Jeffrey Hugo
2022-08-05 3:18 ` Bagas Sanjaya
2022-08-05 15:48 ` Elliot Berman
2022-08-06 15:31 ` kernel test robot
2022-08-01 21:12 ` [PATCH v2 02/11] dt-bindings: Add binding for gunyah hypervisor Elliot Berman
2022-08-02 7:28 ` Dmitry Baryshkov
2022-08-02 10:54 ` Krzysztof Kozlowski
2022-08-01 21:12 ` [PATCH v2 03/11] arm64: gunyah: Add Gunyah hypercalls ABI Elliot Berman
2022-08-02 13:34 ` Dmitry Baryshkov
2022-08-03 21:15 ` Elliot Berman
2022-08-04 7:04 ` Dmitry Baryshkov
2022-08-01 21:12 ` [PATCH v2 04/11] gunyah: Common types and error codes for Gunyah hypercalls Elliot Berman
2022-08-02 7:33 ` Dmitry Baryshkov
2022-08-03 21:16 ` Elliot Berman
2022-08-02 7:51 ` Dmitry Baryshkov
2022-08-03 21:16 ` Elliot Berman
2022-08-01 21:12 ` [PATCH v2 05/11] virt: gunyah: Add sysfs nodes Elliot Berman
2022-08-02 7:42 ` Dmitry Baryshkov [this message]
2022-08-01 21:12 ` [PATCH v2 06/11] virt: gunyah: Add capabilities bus and devices Elliot Berman
2022-08-02 8:20 ` Dmitry Baryshkov
2022-08-01 21:12 ` [PATCH v2 07/11] gunyah: msgq: Add Gunyah message queues Elliot Berman
2022-08-02 8:14 ` Dmitry Baryshkov
2022-08-08 22:22 ` Elliot Berman
[not found] ` <87zggdven5.wl-maz@kernel.org>
2022-08-09 16:50 ` Elliot Berman
2022-08-23 7:57 ` Dmitry Baryshkov
2022-08-01 21:12 ` [PATCH v2 08/11] gunyah: rsc_mgr: Add resource manager RPC core Elliot Berman
2022-08-01 21:12 ` [PATCH v2 09/11] gunyah: rsc_mgr: Add auxiliary devices for console Elliot Berman
2022-08-02 8:38 ` Dmitry Baryshkov
2022-08-03 21:19 ` Elliot Berman
2022-08-01 21:12 ` [PATCH v2 10/11] gunyah: rsc_mgr: Add RPC for console services Elliot Berman
2022-08-01 21:12 ` [PATCH v2 11/11] gunyah: Add tty console driver for RM Console Serivces Elliot Berman
2022-08-02 8:31 ` Dmitry Baryshkov
2022-08-03 21:15 ` Elliot Berman
2022-08-01 21:27 ` [PATCH v2 00/11] Drivers for gunyah hypervisor Jeffrey Hugo
2022-08-01 21:31 ` Elliot Berman
2022-08-02 9:24 ` Dmitry Baryshkov
2022-08-08 23:38 ` Elliot Berman
2022-08-09 13:13 ` Robin Murphy
2022-08-10 0:07 ` Elliot Berman
2022-08-10 4:12 ` Jassi Brar
2022-08-18 18:10 ` Elliot Berman
2022-08-23 8:01 ` Dmitry Baryshkov
2022-08-04 8:26 ` Bagas Sanjaya
2022-08-04 21:48 ` Elliot Berman
2022-08-05 2:15 ` Bagas Sanjaya
2022-08-05 7:45 ` Marc Zyngier
[not found] <20220223233729.1571114-1-quic_eberman@quicinc.com>
2022-07-14 21:29 ` [PATCH v2 00/11] Gunyah Hypervisor drivers Elliot Berman
2022-07-14 21:29 ` [PATCH v2 05/11] virt: gunyah: Add sysfs nodes Elliot Berman
2022-07-14 22:41 ` Randy Dunlap
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=5f22bf9c-3694-0f08-d472-a3c952c081e7@linaro.org \
--to=dmitry.baryshkov@linaro.org \
--cc=agross@kernel.org \
--cc=bjorn.andersson@linaro.org \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=lorenzo.pieralisi@arm.com \
--cc=maz@kernel.org \
--cc=quic_cvanscha@quicinc.com \
--cc=quic_eberman@quicinc.com \
--cc=quic_mnalajal@quicinc.com \
--cc=quic_svaddagi@quicinc.com \
--cc=quic_tsoni@quicinc.com \
--cc=robh+dt@kernel.org \
--cc=sudeep.holla@arm.com \
--cc=will@kernel.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).