2023-01-20 23:35:15

by Elliot Berman

[permalink] [raw]
Subject: [PATCH v9 00/27] Drivers for gunyah hypervisor

Gunyah is a Type-1 hypervisor independent of any
high-level OS kernel, and runs in a higher CPU privilege level. It does
not depend on any lower-privileged OS kernel/code for its core
functionality. This increases its security and can support a much smaller
trusted computing base than a Type-2 hypervisor.

Gunyah is an open source hypervisor. The source repo is available at
https://github.com/quic/gunyah-hypervisor.

The diagram below shows the architecture.

::

VM A VM B
+-----+ +-----+ | +-----+ +-----+ +-----+
| | | | | | | | | | |
EL0 | APP | | APP | | | APP | | APP | | APP |
| | | | | | | | | | |
+-----+ +-----+ | +-----+ +-----+ +-----+
---------------------|-------------------------
+--------------+ | +----------------------+
| | | | |
EL1 | Linux Kernel | | |Linux kernel/Other OS | ...
| | | | |
+--------------+ | +----------------------+
--------hvc/smc------|------hvc/smc------------
+----------------------------------------+
| |
EL2 | Gunyah Hypervisor |
| |
+----------------------------------------+

Gunyah provides these following features.

- Threads and Scheduling: The scheduler schedules virtual CPUs (VCPUs) on
physical CPUs and enables time-sharing of the CPUs.
- Memory Management: Gunyah tracks memory ownership and use of all memory
under its control. Memory partitioning between VMs is a fundamental
security feature.
- Interrupt Virtualization: All interrupts are handled in the hypervisor
and routed to the assigned VM.
- Inter-VM Communication: There are several different mechanisms provided
for communicating between VMs.
- Device Virtualization: Para-virtualization of devices is supported using
inter-VM communication. Low level system features and devices such as
interrupt controllers are supported with emulation where required.

This series adds the basic framework for detecting that Linux is running
under Gunyah as a virtual machine, communication with the Gunyah Resource
Manager, and a virtual machine manager capable of launching virtual machines.

Changes in v9:
- Refactor Gunyah API flags to be exposed as feature flags at kernel level
- Move mbox client cleanup into gunyah_msgq_remove()
- Simplify gh_rm_call return value and response payload
- Clean-up/error handling/little endian suggestions by Srivatsa and Alex in v8 series

Changes in v8: https://lore.kernel.org/all/[email protected]/
- Treat VM manager as a library of RM
- Add patches 21-28 as RFC to support proxy-scheduled vCPUs and necessary bits to support virtio
from Gunyah userspace

Changes in v7: https://lore.kernel.org/all/[email protected]/
- Refactor to remove gunyah RM bus
- Refactor allow multiple RM device instances
- Bump UAPI to start at 0x0
- Refactor QCOM SCM's platform hooks to allow CONFIG_QCOM_SCM=Y/CONFIG_GUNYAH=M combinations

Changes in v6: https://lore.kernel.org/all/[email protected]/
- *Replace gunyah-console with gunyah VM Manager*
- Move include/asm-generic/gunyah.h into include/linux/gunyah.h
- s/gunyah_msgq/gh_msgq/
- Minor tweaks and documentation tidying based on comments from Jiri, Greg, Arnd, Dmitry, and Bagas.

Changes in v5: https://lore.kernel.org/all/[email protected]/
- Dropped sysfs nodes
- Switch from aux bus to Gunyah RM bus for the subdevices
- Cleaning up RM console

Changes in v4: https://lore.kernel.org/all/[email protected]/
- Tidied up documentation throughout based on questions/feedback received
- Switched message queue implementation to use mailboxes
- Renamed "gunyah_device" as "gunyah_resource"

Changes in v3: https://lore.kernel.org/all/[email protected]/
- /Maintained/Supported/ in MAINTAINERS
- Tidied up documentation throughout based on questions/feedback received
- Moved hypercalls into arch/arm64/gunyah/; following hyper-v's implementation
- Drop opaque typedefs
- Move sysfs nodes under /sys/hypervisor/gunyah/
- Moved Gunyah console driver to drivers/tty/
- Reworked gunyah_device design to drop the Gunyah bus.

Changes in v2: https://lore.kernel.org/all/[email protected]/
- DT bindings clean up
- Switch hypercalls to follow SMCCC

v1: https://lore.kernel.org/all/[email protected]/

Elliot Berman (27):
docs: gunyah: Introduce Gunyah Hypervisor
dt-bindings: Add binding for gunyah hypervisor
gunyah: Common types and error codes for Gunyah hypercalls
virt: gunyah: Add hypercalls to identify Gunyah
virt: gunyah: Identify hypervisor version
mailbox: Allow direct registration to a channel
virt: gunyah: msgq: Add hypercalls to send and receive messages
mailbox: Add Gunyah message queue mailbox
gunyah: rsc_mgr: Add resource manager RPC core
gunyah: rsc_mgr: Add VM lifecycle RPC
gunyah: vm_mgr: Introduce basic VM Manager
gunyah: rsc_mgr: Add RPC for sharing memory
gunyah: vm_mgr: Add/remove user memory regions
gunyah: vm_mgr: Add ioctls to support basic non-proxy VM boot
samples: Add sample userspace Gunyah VM Manager
gunyah: rsc_mgr: Add platform ops on mem_lend/mem_reclaim
firmware: qcom_scm: Use fixed width src vm bitmap
firmware: qcom_scm: Register Gunyah platform ops
docs: gunyah: Document Gunyah VM Manager
virt: gunyah: Translate gh_rm_hyp_resource into gunyah_resource
gunyah: vm_mgr: Add framework to add VM Functions
virt: gunyah: Add resource tickets
virt: gunyah: Add IO handlers
virt: gunyah: Add proxy-scheduled vCPUs
virt: gunyah: Add hypercalls for sending doorbell
virt: gunyah: Add irqfd interface
virt: gunyah: Add ioeventfd

.../bindings/firmware/gunyah-hypervisor.yaml | 82 ++
.../userspace-api/ioctl/ioctl-number.rst | 1 +
Documentation/virt/gunyah/index.rst | 114 +++
Documentation/virt/gunyah/message-queue.rst | 69 ++
Documentation/virt/gunyah/vm-manager.rst | 187 ++++
Documentation/virt/index.rst | 1 +
MAINTAINERS | 13 +
arch/arm64/Kbuild | 1 +
arch/arm64/gunyah/Makefile | 3 +
arch/arm64/gunyah/gunyah_hypercall.c | 149 ++++
arch/arm64/include/asm/gunyah.h | 23 +
drivers/firmware/Kconfig | 2 +
drivers/firmware/qcom_scm.c | 112 ++-
drivers/mailbox/Makefile | 2 +
drivers/mailbox/gunyah-msgq.c | 214 +++++
drivers/mailbox/mailbox.c | 96 +-
drivers/mailbox/omap-mailbox.c | 19 +-
drivers/mailbox/pcc.c | 18 +-
drivers/misc/fastrpc.c | 2 +-
drivers/net/wireless/ath/ath10k/qmi.c | 4 +-
drivers/remoteproc/qcom_q6v5_mss.c | 8 +-
drivers/soc/qcom/rmtfs_mem.c | 2 +-
drivers/virt/Kconfig | 2 +
drivers/virt/Makefile | 1 +
drivers/virt/gunyah/Kconfig | 46 +
drivers/virt/gunyah/Makefile | 11 +
drivers/virt/gunyah/gunyah.c | 54 ++
drivers/virt/gunyah/gunyah_ioeventfd.c | 109 +++
drivers/virt/gunyah/gunyah_irqfd.c | 166 ++++
drivers/virt/gunyah/gunyah_platform_hooks.c | 63 ++
drivers/virt/gunyah/gunyah_vcpu.c | 358 ++++++++
drivers/virt/gunyah/rsc_mgr.c | 833 ++++++++++++++++++
drivers/virt/gunyah/rsc_mgr.h | 160 ++++
drivers/virt/gunyah/rsc_mgr_rpc.c | 457 ++++++++++
drivers/virt/gunyah/vm_mgr.c | 669 ++++++++++++++
drivers/virt/gunyah/vm_mgr.h | 70 ++
drivers/virt/gunyah/vm_mgr_mm.c | 247 ++++++
include/linux/gunyah.h | 187 ++++
include/linux/gunyah_rsc_mgr.h | 141 +++
include/linux/gunyah_vm_mgr.h | 107 +++
include/linux/mailbox_client.h | 1 +
include/linux/qcom_scm.h | 2 +-
include/uapi/linux/gunyah.h | 115 +++
samples/Kconfig | 10 +
samples/Makefile | 1 +
samples/gunyah/.gitignore | 2 +
samples/gunyah/Makefile | 6 +
samples/gunyah/gunyah_vmm.c | 270 ++++++
samples/gunyah/sample_vm.dts | 69 ++
49 files changed, 5207 insertions(+), 72 deletions(-)
create mode 100644 Documentation/devicetree/bindings/firmware/gunyah-hypervisor.yaml
create mode 100644 Documentation/virt/gunyah/index.rst
create mode 100644 Documentation/virt/gunyah/message-queue.rst
create mode 100644 Documentation/virt/gunyah/vm-manager.rst
create mode 100644 arch/arm64/gunyah/Makefile
create mode 100644 arch/arm64/gunyah/gunyah_hypercall.c
create mode 100644 arch/arm64/include/asm/gunyah.h
create mode 100644 drivers/mailbox/gunyah-msgq.c
create mode 100644 drivers/virt/gunyah/Kconfig
create mode 100644 drivers/virt/gunyah/Makefile
create mode 100644 drivers/virt/gunyah/gunyah.c
create mode 100644 drivers/virt/gunyah/gunyah_ioeventfd.c
create mode 100644 drivers/virt/gunyah/gunyah_irqfd.c
create mode 100644 drivers/virt/gunyah/gunyah_platform_hooks.c
create mode 100644 drivers/virt/gunyah/gunyah_vcpu.c
create mode 100644 drivers/virt/gunyah/rsc_mgr.c
create mode 100644 drivers/virt/gunyah/rsc_mgr.h
create mode 100644 drivers/virt/gunyah/rsc_mgr_rpc.c
create mode 100644 drivers/virt/gunyah/vm_mgr.c
create mode 100644 drivers/virt/gunyah/vm_mgr.h
create mode 100644 drivers/virt/gunyah/vm_mgr_mm.c
create mode 100644 include/linux/gunyah.h
create mode 100644 include/linux/gunyah_rsc_mgr.h
create mode 100644 include/linux/gunyah_vm_mgr.h
create mode 100644 include/uapi/linux/gunyah.h
create mode 100644 samples/gunyah/.gitignore
create mode 100644 samples/gunyah/Makefile
create mode 100644 samples/gunyah/gunyah_vmm.c
create mode 100644 samples/gunyah/sample_vm.dts


base-commit: 3daed6345d5880464f46adab871d208e1baa2f3a
--
2.39.0


2023-01-20 23:47:24

by Elliot Berman

[permalink] [raw]
Subject: [PATCH v9 07/27] virt: gunyah: msgq: Add hypercalls to send and receive messages

Add hypercalls to send and receive messages on a Gunyah message queue.

Signed-off-by: Elliot Berman <[email protected]>
---
arch/arm64/gunyah/gunyah_hypercall.c | 33 ++++++++++++++++++++++++++++
include/linux/gunyah.h | 5 +++++
2 files changed, 38 insertions(+)

diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c
index ffed4b71641f..d93ad2c08479 100644
--- a/arch/arm64/gunyah/gunyah_hypercall.c
+++ b/arch/arm64/gunyah/gunyah_hypercall.c
@@ -13,6 +13,8 @@ static const uint32_t gunyah_known_uuids[][4] = {
};

#define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000)
+#define GH_HYPERCALL_MSGQ_SEND GH_HYPERCALL(0x001B)
+#define GH_HYPERCALL_MSGQ_RECV GH_HYPERCALL(0x001C)

/**
* gh_hypercall_get_uid() - Returns a UID when running under a Gunyah hypervisor
@@ -71,5 +73,36 @@ void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identi
}
EXPORT_SYMBOL_GPL(gh_hypercall_hyp_identify);

+int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_flags, bool *ready)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_SEND, capid, size, buff, tx_flags, 0, &res);
+
+ if (res.a0)
+ return res.a0;
+
+ *ready = res.a1;
+
+ return res.a0;
+}
+EXPORT_SYMBOL_GPL(gh_hypercall_msgq_send);
+
+int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t *recv_size, bool *ready)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_RECV, capid, buff, size, 0, &res);
+
+ if (res.a0)
+ return res.a0;
+
+ *recv_size = res.a1;
+ *ready = res.a2;
+
+ return res.a0;
+}
+EXPORT_SYMBOL_GPL(gh_hypercall_msgq_recv);
+
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls");
diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h
index 6724d1264d58..b5f61c14ec1e 100644
--- a/include/linux/gunyah.h
+++ b/include/linux/gunyah.h
@@ -104,4 +104,9 @@ struct gh_hypercall_hyp_identify_resp {

void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identity);

+#define GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH BIT(0)
+
+int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_flags, bool *ready);
+int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t *recv_size, bool *ready);
+
#endif
--
2.39.0

2023-01-21 00:07:26

by Elliot Berman

[permalink] [raw]
Subject: [PATCH v9 26/27] virt: gunyah: Add irqfd interface

Enable support for creating irqfds which can raise an interrupt on a
Gunyah virtual machine. irqfds are exposed to userspace as a Gunyah VM
function with the name "irqfd". If the VM devicetree is not configured
to create a doorbell with the corresponding label, userspace will still
be able to assert the eventfd but no interrupt will be raised on the
guest.

Co-developed-by: Prakruthi Deepak Heragu <[email protected]>
Signed-off-by: Prakruthi Deepak Heragu <[email protected]>
Signed-off-by: Elliot Berman <[email protected]>
---
Documentation/virt/gunyah/vm-manager.rst | 22 +++
drivers/virt/gunyah/Kconfig | 9 ++
drivers/virt/gunyah/Makefile | 1 +
drivers/virt/gunyah/gunyah_irqfd.c | 166 +++++++++++++++++++++++
include/linux/gunyah.h | 5 +
include/uapi/linux/gunyah.h | 11 +-
6 files changed, 213 insertions(+), 1 deletion(-)
create mode 100644 drivers/virt/gunyah/gunyah_irqfd.c

diff --git a/Documentation/virt/gunyah/vm-manager.rst b/Documentation/virt/gunyah/vm-manager.rst
index d11267d59802..b6cf8db826b8 100644
--- a/Documentation/virt/gunyah/vm-manager.rst
+++ b/Documentation/virt/gunyah/vm-manager.rst
@@ -142,3 +142,25 @@ The vcpu type will register with the VM Manager to expect to control
vCPU number `vcpu_id`. It returns a file descriptor allowing interaction with
the vCPU. See the Gunyah vCPU API description sections for interacting with
the Gunyah vCPU file descriptors.
+
+Type: "irqfd"
+^^^^^^^^^^^^^
+
+::
+
+ struct gh_fn_irqfd_arg {
+ __u32 fd;
+ __u32 label;
+ #define GH_IRQFD_LEVEL (1UL << 0)
+ #define GH_IRQFD_DEASSIGN (1UL << 1)
+ __u32 flags;
+ };
+
+Allows setting an eventfd to directly trigger a guest interrupt.
+irqfd.fd specifies the file descriptor to use as the eventfd.
+irqfd.label corresponds to the doorbell label used in the guest VM's devicetree.
+The irqfd is removed using the GH_IRQFD_DEASSIGN flag and specifying at least
+the irqfd.label.
+
+GH_IRQFD_LEVEL configures the corresponding doorbell to behave like a level
+triggered interrupt.
diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig
index 4c1c6110b50e..2cde24d429d1 100644
--- a/drivers/virt/gunyah/Kconfig
+++ b/drivers/virt/gunyah/Kconfig
@@ -26,3 +26,12 @@ config GUNYAH_VCPU
VMMs can also handle stage 2 faults of the vCPUs.

Say Y/M here if unsure and you want to support Gunyah VMMs.
+
+config GUNYAH_IRQFD
+ tristate "Gunyah irqfd interface"
+ depends on GUNYAH
+ help
+ Enable kernel support for creating irqfds which can raise an interrupt
+ on Gunyah virtual machine.
+
+ Say Y/M here if unsure and you want to support Gunyah VMMs.
diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile
index 2d1b604a7b03..6cf756bfa3c2 100644
--- a/drivers/virt/gunyah/Makefile
+++ b/drivers/virt/gunyah/Makefile
@@ -7,3 +7,4 @@ gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mm.o
obj-$(CONFIG_GUNYAH) += gunyah_rsc_mgr.o

obj-$(CONFIG_GUNYAH_VCPU) += gunyah_vcpu.o
+obj-$(CONFIG_GUNYAH_IRQFD) += gunyah_irqfd.o
diff --git a/drivers/virt/gunyah/gunyah_irqfd.c b/drivers/virt/gunyah/gunyah_irqfd.c
new file mode 100644
index 000000000000..a3be9ca2377a
--- /dev/null
+++ b/drivers/virt/gunyah/gunyah_irqfd.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include <linux/eventfd.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/gunyah.h>
+#include <linux/gunyah_vm_mgr.h>
+#include <linux/kref.h>
+#include <linux/module.h>
+#include <linux/poll.h>
+#include <linux/printk.h>
+
+#include <uapi/linux/gunyah.h>
+
+struct gunyah_irqfd {
+ struct gunyah_resource *ghrsc;
+ struct gunyah_vm_resource_ticket ticket;
+ struct gunyah_vm_function *f;
+
+ struct kref kref;
+ bool level;
+
+ struct eventfd_ctx *ctx;
+ wait_queue_entry_t wait;
+ poll_table pt;
+ struct fd fd;
+};
+
+static void gh_irqfd_cleanup(struct kref *kref)
+{
+ struct gunyah_irqfd *irqfd = container_of(kref, struct gunyah_irqfd, kref);
+
+ kfree(irqfd);
+}
+
+static int irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode, int sync, void *key)
+{
+ struct gunyah_irqfd *irqfd = container_of(wait, struct gunyah_irqfd, wait);
+ __poll_t flags = key_to_poll(key);
+ u64 enable_mask = GH_DBL_NONBLOCK;
+ u64 old_flags;
+ int ret = 0;
+
+ if (flags & EPOLLIN) {
+ if (irqfd->ghrsc) {
+ ret = gh_hypercall_dbl_send(irqfd->ghrsc->capid, enable_mask, &old_flags);
+ if (ret)
+ pr_err("Failed to assert irq %d\n", irqfd->f->fn.irqfd.label);
+ }
+ }
+
+ return 0;
+}
+
+static void irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh, poll_table *pt)
+{
+ struct gunyah_irqfd *irq_ctx = container_of(pt, struct gunyah_irqfd, pt);
+
+ add_wait_queue(wqh, &irq_ctx->wait);
+}
+
+static int gunyah_irqfd_populate(struct gunyah_vm_resource_ticket *ticket,
+ struct gunyah_resource *ghrsc)
+{
+ struct gunyah_irqfd *irqfd = container_of(ticket, struct gunyah_irqfd, ticket);
+ u64 enable_mask = GH_DBL_NONBLOCK;
+ u64 ack_mask = ~0;
+ int ret = 0;
+
+ irqfd->ghrsc = ghrsc;
+ if (irqfd->level) {
+ ret = gh_hypercall_dbl_set_mask(irqfd->ghrsc->capid, enable_mask, ack_mask);
+ if (ret)
+ pr_warn("irq %d couldn't be set as level triggered. Might cause IRQ storm if asserted\n",
+ irqfd->f->fn.irqfd.label);
+ }
+ kref_get(&irqfd->kref);
+
+ return 0;
+}
+
+static void gunyah_irqfd_unpopulate(struct gunyah_vm_resource_ticket *ticket,
+ struct gunyah_resource *ghrsc)
+{
+ struct gunyah_irqfd *irqfd = container_of(ticket, struct gunyah_irqfd, ticket);
+ u64 cnt;
+
+ eventfd_ctx_remove_wait_queue(irqfd->ctx, &irqfd->wait, &cnt);
+ eventfd_ctx_put(irqfd->ctx);
+ fdput(irqfd->fd);
+ irqfd->ctx = NULL;
+ irqfd->fd.file = NULL;
+ irqfd->ghrsc = NULL;
+ kref_put(&irqfd->kref, gh_irqfd_cleanup);
+}
+
+static long gunyah_irqfd_bind(struct gunyah_vm_function *f)
+{
+ __poll_t events;
+ struct gunyah_irqfd *irqfd;
+ long r;
+
+ irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
+ if (!irqfd)
+ return -ENOMEM;
+
+ irqfd->f = f;
+ f->data = irqfd;
+
+ irqfd->fd = fdget(f->fn.irqfd.fd);
+ if (!irqfd->fd.file) {
+ r = -EBADF;
+ goto err_free;
+ }
+
+ irqfd->ctx = eventfd_ctx_fileget(irqfd->fd.file);
+ if (IS_ERR(irqfd->ctx)) {
+ r = PTR_ERR(irqfd->ctx);
+ goto err_fdput;
+ }
+
+ if (f->fn.irqfd.flags & GH_IRQFD_LEVEL)
+ irqfd->level = true;
+
+ init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
+ init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc);
+ kref_init(&irqfd->kref);
+
+ irqfd->ticket.resource_type = GUNYAH_RESOURCE_TYPE_BELL_TX;
+ irqfd->ticket.label = f->fn.irqfd.label;
+ irqfd->ticket.owner = THIS_MODULE;
+ irqfd->ticket.populate = gunyah_irqfd_populate;
+ irqfd->ticket.unpopulate = gunyah_irqfd_unpopulate;
+
+ r = ghvm_add_resource_ticket(f->ghvm, &irqfd->ticket);
+ if (r)
+ goto err_ctx;
+
+ events = vfs_poll(irqfd->fd.file, &irqfd->pt);
+ if (events & EPOLLIN)
+ pr_warn("Premature injection of interrupt\n");
+
+ return 0;
+err_ctx:
+ eventfd_ctx_put(irqfd->ctx);
+err_fdput:
+ fdput(irqfd->fd);
+err_free:
+ kfree(irqfd);
+ return r;
+}
+
+static void gunyah_irqfd_release(struct gunyah_vm_function *f)
+{
+ struct gunyah_irqfd *irqfd = f->data;
+
+ /* unpopulate will trigger clean up of the eventfd */
+ ghvm_remove_resource_ticket(irqfd->f->ghvm, &irqfd->ticket);
+}
+
+DECLARE_GUNYAH_VM_FUNCTION_INIT(irqfd, gunyah_irqfd_bind, gunyah_irqfd_release);
+MODULE_DESCRIPTION("Gunyah irqfds");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h
index ac4879940c10..6b363707a901 100644
--- a/include/linux/gunyah.h
+++ b/include/linux/gunyah.h
@@ -33,6 +33,11 @@ struct gunyah_resource {
u32 rm_label;
};

+/**
+ * Gunyah Doorbells
+ */
+#define GH_DBL_NONBLOCK BIT(32)
+
/**
* Gunyah Message Queues
*/
diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h
index b4afb11f538a..a947f0317ca9 100644
--- a/include/uapi/linux/gunyah.h
+++ b/include/uapi/linux/gunyah.h
@@ -57,10 +57,19 @@ struct gh_fn_vcpu_arg {
__u32 vcpu_id;
};

+struct gh_fn_irqfd_arg {
+ __u32 fd;
+ __u32 label;
+#define GH_IRQFD_LEVEL (1UL << 0)
+#define GH_IRQFD_DEASSIGN (1UL << 1)
+ __u32 flags;
+};
+
struct gh_vm_function {
char name[GUNYAH_FUNCTION_NAME_SIZE];
union {
- struct gh_device_vcpu_arg vcpu;
+ struct gh_fn_vcpu_arg vcpu;
+ struct gh_fn_irqfd_arg irqfd;
char data[GUNYAH_FUNCTION_MAX_ARG_SIZE];
};
};
--
2.39.0

2023-01-20 22:50:12

by Elliot Berman

[permalink] [raw]
Subject: [PATCH v9 17/27] firmware: qcom_scm: Use fixed width src vm bitmap

The maximum VMID for assign_mem is 63. Use a u64 to represent this
bitmap instead of architecture-dependent "unsigned int" which varies in
size on 32-bit and 64-bit platforms.

Acked-by: Kalle Valo <[email protected]> [ath10k]
Signed-off-by: Elliot Berman <[email protected]>
---
drivers/firmware/qcom_scm.c | 12 +++++++-----
drivers/misc/fastrpc.c | 2 +-
drivers/net/wireless/ath/ath10k/qmi.c | 4 ++--
drivers/remoteproc/qcom_q6v5_mss.c | 8 ++++----
drivers/soc/qcom/rmtfs_mem.c | 2 +-
include/linux/qcom_scm.h | 2 +-
6 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/firmware/qcom_scm.c b/drivers/firmware/qcom_scm.c
index cdbfe54c8146..92763dce6477 100644
--- a/drivers/firmware/qcom_scm.c
+++ b/drivers/firmware/qcom_scm.c
@@ -898,7 +898,7 @@ static int __qcom_scm_assign_mem(struct device *dev, phys_addr_t mem_region,
* Return negative errno on failure or 0 on success with @srcvm updated.
*/
int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,
- unsigned int *srcvm,
+ u64 *srcvm,
const struct qcom_scm_vmperm *newvm,
unsigned int dest_cnt)
{
@@ -915,9 +915,9 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,
__le32 *src;
void *ptr;
int ret, i, b;
- unsigned long srcvm_bits = *srcvm;
+ u64 srcvm_bits = *srcvm;

- src_sz = hweight_long(srcvm_bits) * sizeof(*src);
+ src_sz = hweight64(srcvm_bits) * sizeof(*src);
mem_to_map_sz = sizeof(*mem_to_map);
dest_sz = dest_cnt * sizeof(*destvm);
ptr_sz = ALIGN(src_sz, SZ_64) + ALIGN(mem_to_map_sz, SZ_64) +
@@ -930,8 +930,10 @@ int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,
/* Fill source vmid detail */
src = ptr;
i = 0;
- for_each_set_bit(b, &srcvm_bits, BITS_PER_LONG)
- src[i++] = cpu_to_le32(b);
+ for (b = 0; b < BITS_PER_TYPE(u64); b++) {
+ if (srcvm_bits & BIT(b))
+ src[i++] = cpu_to_le32(b);
+ }

/* Fill details of mem buff to map */
mem_to_map = ptr + ALIGN(src_sz, SZ_64);
diff --git a/drivers/misc/fastrpc.c b/drivers/misc/fastrpc.c
index 5310606113fe..67c24b4002b8 100644
--- a/drivers/misc/fastrpc.c
+++ b/drivers/misc/fastrpc.c
@@ -262,7 +262,7 @@ struct fastrpc_channel_ctx {
int domain_id;
int sesscount;
int vmcount;
- u32 perms;
+ u64 perms;
struct qcom_scm_vmperm vmperms[FASTRPC_MAX_VMIDS];
struct rpmsg_device *rpdev;
struct fastrpc_session_ctx session[FASTRPC_MAX_SESSIONS];
diff --git a/drivers/net/wireless/ath/ath10k/qmi.c b/drivers/net/wireless/ath/ath10k/qmi.c
index 3f94fbf83702..a8497a6ea03c 100644
--- a/drivers/net/wireless/ath/ath10k/qmi.c
+++ b/drivers/net/wireless/ath/ath10k/qmi.c
@@ -33,7 +33,7 @@ static int ath10k_qmi_map_msa_permission(struct ath10k_qmi *qmi,
{
struct qcom_scm_vmperm dst_perms[3];
struct ath10k *ar = qmi->ar;
- unsigned int src_perms;
+ u64 src_perms;
u32 perm_count;
int ret;

@@ -65,7 +65,7 @@ static int ath10k_qmi_unmap_msa_permission(struct ath10k_qmi *qmi,
{
struct qcom_scm_vmperm dst_perms;
struct ath10k *ar = qmi->ar;
- unsigned int src_perms;
+ u64 src_perms;
int ret;

src_perms = BIT(QCOM_SCM_VMID_MSS_MSA) | BIT(QCOM_SCM_VMID_WLAN);
diff --git a/drivers/remoteproc/qcom_q6v5_mss.c b/drivers/remoteproc/qcom_q6v5_mss.c
index fddb63cffee0..9e8bde7a7ec4 100644
--- a/drivers/remoteproc/qcom_q6v5_mss.c
+++ b/drivers/remoteproc/qcom_q6v5_mss.c
@@ -227,8 +227,8 @@ struct q6v5 {
bool has_qaccept_regs;
bool has_ext_cntl_regs;
bool has_vq6;
- int mpss_perm;
- int mba_perm;
+ u64 mpss_perm;
+ u64 mba_perm;
const char *hexagon_mdt_image;
int version;
};
@@ -404,7 +404,7 @@ static void q6v5_pds_disable(struct q6v5 *qproc, struct device **pds,
}
}

-static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm,
+static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, u64 *current_perm,
bool local, bool remote, phys_addr_t addr,
size_t size)
{
@@ -939,7 +939,7 @@ static int q6v5_mpss_init_image(struct q6v5 *qproc, const struct firmware *fw,
struct page *page;
dma_addr_t phys;
void *metadata;
- int mdata_perm;
+ u64 mdata_perm;
int xferop_ret;
size_t size;
void *vaddr;
diff --git a/drivers/soc/qcom/rmtfs_mem.c b/drivers/soc/qcom/rmtfs_mem.c
index 0feaae357821..69991e47aa23 100644
--- a/drivers/soc/qcom/rmtfs_mem.c
+++ b/drivers/soc/qcom/rmtfs_mem.c
@@ -30,7 +30,7 @@ struct qcom_rmtfs_mem {

unsigned int client_id;

- unsigned int perms;
+ u64 perms;
};

static ssize_t qcom_rmtfs_mem_show(struct device *dev,
diff --git a/include/linux/qcom_scm.h b/include/linux/qcom_scm.h
index f8335644a01a..77f7b5837216 100644
--- a/include/linux/qcom_scm.h
+++ b/include/linux/qcom_scm.h
@@ -96,7 +96,7 @@ extern int qcom_scm_mem_protect_video_var(u32 cp_start, u32 cp_size,
u32 cp_nonpixel_start,
u32 cp_nonpixel_size);
extern int qcom_scm_assign_mem(phys_addr_t mem_addr, size_t mem_sz,
- unsigned int *src,
+ u64 *src,
const struct qcom_scm_vmperm *newvm,
unsigned int dest_cnt);

--
2.39.0


2023-01-31 16:17:12

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH v9 07/27] virt: gunyah: msgq: Add hypercalls to send and receive messages



On 20/01/2023 22:46, Elliot Berman wrote:
> Add hypercalls to send and receive messages on a Gunyah message queue.
>
> Signed-off-by: Elliot Berman <[email protected]>
> ---
> arch/arm64/gunyah/gunyah_hypercall.c | 33 ++++++++++++++++++++++++++++
> include/linux/gunyah.h | 5 +++++
> 2 files changed, 38 insertions(+)
>
> diff --git a/arch/arm64/gunyah/gunyah_hypercall.c b/arch/arm64/gunyah/gunyah_hypercall.c
> index ffed4b71641f..d93ad2c08479 100644
> --- a/arch/arm64/gunyah/gunyah_hypercall.c
> +++ b/arch/arm64/gunyah/gunyah_hypercall.c
> @@ -13,6 +13,8 @@ static const uint32_t gunyah_known_uuids[][4] = {
> };
>
> #define GH_HYPERCALL_HYP_IDENTIFY GH_HYPERCALL(0x0000)
> +#define GH_HYPERCALL_MSGQ_SEND GH_HYPERCALL(0x001B)
> +#define GH_HYPERCALL_MSGQ_RECV GH_HYPERCALL(0x001C)
>
> /**
> * gh_hypercall_get_uid() - Returns a UID when running under a Gunyah hypervisor
> @@ -71,5 +73,36 @@ void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identi
> }
> EXPORT_SYMBOL_GPL(gh_hypercall_hyp_identify);
>
> +int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_flags, bool *ready)
> +{
> + struct arm_smccc_res res;
> +
> + arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_SEND, capid, size, buff, tx_flags, 0, &res);
> +
<--
> + if (res.a0)
> + return res.a0;
> +
> + *ready = res.a1;
> +
> + return res.a0;
-->
this can be made more readable with code something like:

if (res.a0 == SMCCC_RET_SUCCESS)
*ready = res.a1;

return res.a0;


> +}
> +EXPORT_SYMBOL_GPL(gh_hypercall_msgq_send);
> +
> +int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t *recv_size, bool *ready)
> +{
> + struct arm_smccc_res res;
> +
> + arm_smccc_1_1_hvc(GH_HYPERCALL_MSGQ_RECV, capid, buff, size, 0, &res);
> +
> + if (res.a0)
> + return res.a0;
> +
> + *recv_size = res.a1;
> + *ready = res.a2;
> +
same comment.


> + return res.a0;
> +}
> +EXPORT_SYMBOL_GPL(gh_hypercall_msgq_recv);
> +
> MODULE_LICENSE("GPL");
> MODULE_DESCRIPTION("Gunyah Hypervisor Hypercalls");
> diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h
> index 6724d1264d58..b5f61c14ec1e 100644
> --- a/include/linux/gunyah.h
> +++ b/include/linux/gunyah.h
> @@ -104,4 +104,9 @@ struct gh_hypercall_hyp_identify_resp {
>
> void gh_hypercall_hyp_identify(struct gh_hypercall_hyp_identify_resp *hyp_identity);
>
> +#define GH_HYPERCALL_MSGQ_TX_FLAGS_PUSH BIT(0)
Please move unrelated changes from this patch to the patch that
actually uses these.

> +
> +int gh_hypercall_msgq_send(u64 capid, size_t size, uintptr_t buff, int tx_flags, bool *ready);
> +int gh_hypercall_msgq_recv(u64 capid, uintptr_t buff, size_t size, size_t *recv_size, bool *ready);
> +
> #endif

2023-02-07 14:35:31

by Srinivas Kandagatla

[permalink] [raw]
Subject: Re: [PATCH v9 26/27] virt: gunyah: Add irqfd interface



On 20/01/2023 22:46, Elliot Berman wrote:
> Enable support for creating irqfds which can raise an interrupt on a
> Gunyah virtual machine. irqfds are exposed to userspace as a Gunyah VM
> function with the name "irqfd". If the VM devicetree is not configured
> to create a doorbell with the corresponding label, userspace will still
> be able to assert the eventfd but no interrupt will be raised on the
> guest.
>
> Co-developed-by: Prakruthi Deepak Heragu <[email protected]>
> Signed-off-by: Prakruthi Deepak Heragu <[email protected]>
> Signed-off-by: Elliot Berman <[email protected]>
> ---
> Documentation/virt/gunyah/vm-manager.rst | 22 +++
> drivers/virt/gunyah/Kconfig | 9 ++
> drivers/virt/gunyah/Makefile | 1 +
> drivers/virt/gunyah/gunyah_irqfd.c | 166 +++++++++++++++++++++++
> include/linux/gunyah.h | 5 +
> include/uapi/linux/gunyah.h | 11 +-
> 6 files changed, 213 insertions(+), 1 deletion(-)
> create mode 100644 drivers/virt/gunyah/gunyah_irqfd.c
>
> diff --git a/Documentation/virt/gunyah/vm-manager.rst b/Documentation/virt/gunyah/vm-manager.rst
> index d11267d59802..b6cf8db826b8 100644
> --- a/Documentation/virt/gunyah/vm-manager.rst
> +++ b/Documentation/virt/gunyah/vm-manager.rst
> @@ -142,3 +142,25 @@ The vcpu type will register with the VM Manager to expect to control
> vCPU number `vcpu_id`. It returns a file descriptor allowing interaction with
> the vCPU. See the Gunyah vCPU API description sections for interacting with
> the Gunyah vCPU file descriptors.
> +
> +Type: "irqfd"
> +^^^^^^^^^^^^^
> +
> +::
> +
> + struct gh_fn_irqfd_arg {
> + __u32 fd;
> + __u32 label;
> + #define GH_IRQFD_LEVEL (1UL << 0)
> + #define GH_IRQFD_DEASSIGN (1UL << 1)
> + __u32 flags;
> + };
> +
> +Allows setting an eventfd to directly trigger a guest interrupt.
> +irqfd.fd specifies the file descriptor to use as the eventfd.
> +irqfd.label corresponds to the doorbell label used in the guest VM's devicetree.
> +The irqfd is removed using the GH_IRQFD_DEASSIGN flag and specifying at least
> +the irqfd.label.
> +
> +GH_IRQFD_LEVEL configures the corresponding doorbell to behave like a level
> +triggered interrupt.
> diff --git a/drivers/virt/gunyah/Kconfig b/drivers/virt/gunyah/Kconfig
> index 4c1c6110b50e..2cde24d429d1 100644
> --- a/drivers/virt/gunyah/Kconfig
> +++ b/drivers/virt/gunyah/Kconfig
> @@ -26,3 +26,12 @@ config GUNYAH_VCPU
> VMMs can also handle stage 2 faults of the vCPUs.
>
> Say Y/M here if unsure and you want to support Gunyah VMMs.
> +
> +config GUNYAH_IRQFD
> + tristate "Gunyah irqfd interface"
> + depends on GUNYAH
> + help
> + Enable kernel support for creating irqfds which can raise an interrupt
> + on Gunyah virtual machine.
> +
> + Say Y/M here if unsure and you want to support Gunyah VMMs.
> diff --git a/drivers/virt/gunyah/Makefile b/drivers/virt/gunyah/Makefile
> index 2d1b604a7b03..6cf756bfa3c2 100644
> --- a/drivers/virt/gunyah/Makefile
> +++ b/drivers/virt/gunyah/Makefile
> @@ -7,3 +7,4 @@ gunyah_rsc_mgr-y += rsc_mgr.o rsc_mgr_rpc.o vm_mgr.o vm_mgr_mm.o
> obj-$(CONFIG_GUNYAH) += gunyah_rsc_mgr.o
>
> obj-$(CONFIG_GUNYAH_VCPU) += gunyah_vcpu.o
> +obj-$(CONFIG_GUNYAH_IRQFD) += gunyah_irqfd.o
> diff --git a/drivers/virt/gunyah/gunyah_irqfd.c b/drivers/virt/gunyah/gunyah_irqfd.c
> new file mode 100644
> index 000000000000..a3be9ca2377a
> --- /dev/null
> +++ b/drivers/virt/gunyah/gunyah_irqfd.c
> @@ -0,0 +1,166 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
> + */
> +
> +#include <linux/eventfd.h>
> +#include <linux/file.h>
> +#include <linux/fs.h>
> +#include <linux/gunyah.h>
> +#include <linux/gunyah_vm_mgr.h>
> +#include <linux/kref.h>
> +#include <linux/module.h>
> +#include <linux/poll.h>
> +#include <linux/printk.h>
> +
> +#include <uapi/linux/gunyah.h>
> +
> +struct gunyah_irqfd {
> + struct gunyah_resource *ghrsc;
> + struct gunyah_vm_resource_ticket ticket;
> + struct gunyah_vm_function *f;
> +
> + struct kref kref;
> + bool level;
> +
> + struct eventfd_ctx *ctx;
> + wait_queue_entry_t wait;
> + poll_table pt;
> + struct fd fd;
> +};
> +
> +static void gh_irqfd_cleanup(struct kref *kref)
> +{
> + struct gunyah_irqfd *irqfd = container_of(kref, struct gunyah_irqfd, kref);
> +
> + kfree(irqfd);
> +}
> +
> +static int irqfd_wakeup(wait_queue_entry_t *wait, unsigned int mode, int sync, void *key)
> +{
> + struct gunyah_irqfd *irqfd = container_of(wait, struct gunyah_irqfd, wait);
> + __poll_t flags = key_to_poll(key);
> + u64 enable_mask = GH_DBL_NONBLOCK;
> + u64 old_flags;
> + int ret = 0;
> +
> + if (flags & EPOLLIN) {
> + if (irqfd->ghrsc) {
> + ret = gh_hypercall_dbl_send(irqfd->ghrsc->capid, enable_mask, &old_flags);
> + if (ret)
> + pr_err("Failed to assert irq %d\n", irqfd->f->fn.irqfd.label);
> + }
> + }
> +
> + return 0;
> +}
> +
> +static void irqfd_ptable_queue_proc(struct file *file, wait_queue_head_t *wqh, poll_table *pt)
> +{
> + struct gunyah_irqfd *irq_ctx = container_of(pt, struct gunyah_irqfd, pt);
> +
> + add_wait_queue(wqh, &irq_ctx->wait);
> +}
> +
> +static int gunyah_irqfd_populate(struct gunyah_vm_resource_ticket *ticket,
> + struct gunyah_resource *ghrsc)
> +{
> + struct gunyah_irqfd *irqfd = container_of(ticket, struct gunyah_irqfd, ticket);
> + u64 enable_mask = GH_DBL_NONBLOCK;
> + u64 ack_mask = ~0;
> + int ret = 0;
> +
> + irqfd->ghrsc = ghrsc;
> + if (irqfd->level) {
> + ret = gh_hypercall_dbl_set_mask(irqfd->ghrsc->capid, enable_mask, ack_mask);
> + if (ret)
> + pr_warn("irq %d couldn't be set as level triggered. Might cause IRQ storm if asserted\n",
> + irqfd->f->fn.irqfd.label);
> + }
> + kref_get(&irqfd->kref);
> +
> + return 0;
> +}
> +
> +static void gunyah_irqfd_unpopulate(struct gunyah_vm_resource_ticket *ticket,
> + struct gunyah_resource *ghrsc)
> +{
> + struct gunyah_irqfd *irqfd = container_of(ticket, struct gunyah_irqfd, ticket);
> + u64 cnt;
> +
> + eventfd_ctx_remove_wait_queue(irqfd->ctx, &irqfd->wait, &cnt);
> + eventfd_ctx_put(irqfd->ctx);

> + fdput(irqfd->fd);
<--
> + irqfd->ctx = NULL;
> + irqfd->fd.file = NULL;
> + irqfd->ghrsc = NULL;
-->

How do we know that this is the last reference ?

> + kref_put(&irqfd->kref, gh_irqfd_cleanup);
> +}
> +
> +static long gunyah_irqfd_bind(struct gunyah_vm_function *f)
> +{
> + __poll_t events;
> + struct gunyah_irqfd *irqfd;
> + long r;
> +
> + irqfd = kzalloc(sizeof(*irqfd), GFP_KERNEL);
> + if (!irqfd)
> + return -ENOMEM;
> +
> + irqfd->f = f;
> + f->data = irqfd;
> +
> + irqfd->fd = fdget(f->fn.irqfd.fd);
> + if (!irqfd->fd.file) {
> + r = -EBADF;
> + goto err_free;
> + }
> +
> + irqfd->ctx = eventfd_ctx_fileget(irqfd->fd.file);
> + if (IS_ERR(irqfd->ctx)) {
> + r = PTR_ERR(irqfd->ctx);
> + goto err_fdput;
> + }
> +
> + if (f->fn.irqfd.flags & GH_IRQFD_LEVEL)
> + irqfd->level = true;
> +
> + init_waitqueue_func_entry(&irqfd->wait, irqfd_wakeup);
> + init_poll_funcptr(&irqfd->pt, irqfd_ptable_queue_proc);
> + kref_init(&irqfd->kref);
> +
> + irqfd->ticket.resource_type = GUNYAH_RESOURCE_TYPE_BELL_TX;
> + irqfd->ticket.label = f->fn.irqfd.label;
> + irqfd->ticket.owner = THIS_MODULE;
> + irqfd->ticket.populate = gunyah_irqfd_populate;
> + irqfd->ticket.unpopulate = gunyah_irqfd_unpopulate;
> +
> + r = ghvm_add_resource_ticket(f->ghvm, &irqfd->ticket);
> + if (r)
> + goto err_ctx;
> +
> + events = vfs_poll(irqfd->fd.file, &irqfd->pt);
> + if (events & EPOLLIN)
> + pr_warn("Premature injection of interrupt\n");
> +
> + return 0;
> +err_ctx:
kref_put missing?

> + eventfd_ctx_put(irqfd->ctx);
> +err_fdput:
> + fdput(irqfd->fd);
> +err_free:
> + kfree(irqfd);
> + return r;
> +}
> +
> +static void gunyah_irqfd_release(struct gunyah_vm_function *f)
> +{
> + struct gunyah_irqfd *irqfd = f->data;
> +
> + /* unpopulate will trigger clean up of the eventfd */
> + ghvm_remove_resource_ticket(irqfd->f->ghvm, &irqfd->ticket);
> +}
> +
> +DECLARE_GUNYAH_VM_FUNCTION_INIT(irqfd, gunyah_irqfd_bind, gunyah_irqfd_release);
> +MODULE_DESCRIPTION("Gunyah irqfds");
> +MODULE_LICENSE("GPL");
> diff --git a/include/linux/gunyah.h b/include/linux/gunyah.h
> index ac4879940c10..6b363707a901 100644
> --- a/include/linux/gunyah.h
> +++ b/include/linux/gunyah.h
> @@ -33,6 +33,11 @@ struct gunyah_resource {
> u32 rm_label;
> };
>
> +/**
> + * Gunyah Doorbells
> + */
> +#define GH_DBL_NONBLOCK BIT(32)
> +
> /**
> * Gunyah Message Queues
> */
> diff --git a/include/uapi/linux/gunyah.h b/include/uapi/linux/gunyah.h
> index b4afb11f538a..a947f0317ca9 100644
> --- a/include/uapi/linux/gunyah.h
> +++ b/include/uapi/linux/gunyah.h
> @@ -57,10 +57,19 @@ struct gh_fn_vcpu_arg {
> __u32 vcpu_id;
> };
>
> +struct gh_fn_irqfd_arg {
> + __u32 fd;
> + __u32 label;
> +#define GH_IRQFD_LEVEL (1UL << 0)
> +#define GH_IRQFD_DEASSIGN (1UL << 1)
> + __u32 flags;

same issue here, this is not naturaly aligned.

for details take a look at Documentation/driver-api/ioctl.rst

> +};
> +
> struct gh_vm_function {
> char name[GUNYAH_FUNCTION_NAME_SIZE];
> union {
> - struct gh_device_vcpu_arg vcpu;
> + struct gh_fn_vcpu_arg vcpu;
> + struct gh_fn_irqfd_arg irqfd;
> char data[GUNYAH_FUNCTION_MAX_ARG_SIZE];
> };
> };

2023-02-13 08:11:48

by Srivatsa Vaddagiri

[permalink] [raw]
Subject: Re: [PATCH v9 26/27] virt: gunyah: Add irqfd interface

* Elliot Berman <[email protected]> [2023-01-20 14:46:25]:

> +static int gunyah_irqfd_populate(struct gunyah_vm_resource_ticket *ticket,
> + struct gunyah_resource *ghrsc)
> +{
> + struct gunyah_irqfd *irqfd = container_of(ticket, struct gunyah_irqfd, ticket);
> + u64 enable_mask = GH_DBL_NONBLOCK;
> + u64 ack_mask = ~0;
> + int ret = 0;
> +
> + irqfd->ghrsc = ghrsc;
> + if (irqfd->level) {
> + ret = gh_hypercall_dbl_set_mask(irqfd->ghrsc->capid, enable_mask, ack_mask);

We probably want this mask set for both level and edge interrupts.

> + if (ret)
> + pr_warn("irq %d couldn't be set as level triggered. Might cause IRQ storm if asserted\n",
> + irqfd->f->fn.irqfd.label);
> + }
> + kref_get(&irqfd->kref);

Is this kref_get() really needed?

> +
> + return 0;
> +}
> +

2023-03-16 03:19:40

by Bjorn Andersson

[permalink] [raw]
Subject: Re: (subset) [PATCH v9 17/27] firmware: qcom_scm: Use fixed width src vm bitmap

On Fri, 20 Jan 2023 14:46:16 -0800, Elliot Berman wrote:
> The maximum VMID for assign_mem is 63. Use a u64 to represent this
> bitmap instead of architecture-dependent "unsigned int" which varies in
> size on 32-bit and 64-bit platforms.
>
>

Applied, thanks!

[17/27] firmware: qcom_scm: Use fixed width src vm bitmap
commit: 968a26a07f75377afbd4f7bb18ef587a1443c244

Best regards,
--
Bjorn Andersson <[email protected]>