From: joaopeixoto@osyx.tech
To: linux-kernel@vger.kernel.org
Cc: ajd@linux.ibm.com, alex@ghiti.fr, aou@eecs.berkeley.edu,
bagasdotme@gmail.com, catalin.marinas@arm.com,
conor+dt@kernel.org, corbet@lwn.net, dan.j.williams@intel.com,
davidmcerdeira@osyx.tech, devicetree@vger.kernel.org,
dev@kael-k.io, gregkh@linuxfoundation.org, haren@linux.ibm.com,
heiko@sntech.de, joaopeixoto@osyx.tech, jose@osyx.tech,
kever.yang@rock-chips.com, krzk+dt@kernel.org,
linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org,
linux-riscv@lists.infradead.org, maddy@linux.ibm.com,
mani@kernel.org, nathan@kernel.org, neil.armstrong@linaro.org,
palmer@dabbelt.com, pjw@kernel.org,
prabhakar.mahadev-lad.rj@bp.renesas.com, robh@kernel.org,
will@kernel.org
Subject: [PATCH 2/6] virt: bao: Add Bao IPC shared memory driver
Date: Wed, 7 Jan 2026 16:28:25 +0000 [thread overview]
Message-ID: <20260107162829.416885-3-joaopeixoto@osyx.tech> (raw)
In-Reply-To: <20260107162829.416885-1-joaopeixoto@osyx.tech>
From: João Peixoto <joaopeixoto@osyx.tech>
This driver provides an interface for guests running on the Bao
hypervisor to communicate with each other through shared-memory
channels. Each guest is assigned a dedicated read and write region
defined in the device tree.
Userspace can access these regions via standard read/write/mmap
operations. Writes to the write region trigger a hypervisor
notification through an architecture-specific hypercall
(HVC on ARM, SBI ecall on RISC-V).
Signed-off-by: João Peixoto <joaopeixoto@osyx.tech>
---
arch/arm/include/asm/bao.h | 31 ++++
arch/arm64/include/asm/bao.h | 31 ++++
arch/riscv/include/asm/bao.h | 31 ++++
drivers/virt/Kconfig | 2 +
drivers/virt/Makefile | 1 +
drivers/virt/bao/Kconfig | 3 +
drivers/virt/bao/Makefile | 3 +
drivers/virt/bao/ipcshmem/Kconfig | 8 +
drivers/virt/bao/ipcshmem/Makefile | 3 +
drivers/virt/bao/ipcshmem/ipcshmem.c | 255 +++++++++++++++++++++++++++
10 files changed, 368 insertions(+)
create mode 100644 arch/arm/include/asm/bao.h
create mode 100644 arch/arm64/include/asm/bao.h
create mode 100644 arch/riscv/include/asm/bao.h
create mode 100644 drivers/virt/bao/Kconfig
create mode 100644 drivers/virt/bao/Makefile
create mode 100644 drivers/virt/bao/ipcshmem/Kconfig
create mode 100644 drivers/virt/bao/ipcshmem/Makefile
create mode 100644 drivers/virt/bao/ipcshmem/ipcshmem.c
diff --git a/arch/arm/include/asm/bao.h b/arch/arm/include/asm/bao.h
new file mode 100644
index 000000000000..9644d06be705
--- /dev/null
+++ b/arch/arm/include/asm/bao.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Bao Hypervisor Hypercall Interface
+ *
+ * Copyright (c) Bao Project and Contributors. All rights reserved.
+ *
+ * Authors:
+ * João Peixoto <joaopeixoto@osyx.tech>
+ * José Martins <jose@osyx.tech>
+ * David Cerdeira <davidmcerdeira@osyx.tech>
+ */
+
+#ifndef __ASM_ARM_BAO_H
+#define __ASM_ARM_BAO_H
+
+#include <linux/arm-smccc.h>
+
+static inline unsigned long bao_ipcshmem_hypercall(unsigned long hypercall_id,
+ unsigned long ipcshmem_id)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_hvc(ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_32,
+ ARM_SMCCC_OWNER_VENDOR_HYP,
+ hypercall_id),
+ ipcshmem_id, 0, 0, 0, 0, 0, 0, &res);
+
+ return res.a0;
+}
+
+#endif /* __ASM_ARM_BAO_H */
diff --git a/arch/arm64/include/asm/bao.h b/arch/arm64/include/asm/bao.h
new file mode 100644
index 000000000000..a1819966b59b
--- /dev/null
+++ b/arch/arm64/include/asm/bao.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Bao Hypervisor Hypercall Interface
+ *
+ * Copyright (c) Bao Project and Contributors. All rights reserved.
+ *
+ * Authors:
+ * João Peixoto <joaopeixoto@osyx.tech>
+ * José Martins <jose@osyx.tech>
+ * David Cerdeira <davidmcerdeira@osyx.tech>
+ */
+
+#ifndef __ASM_ARM64_BAO_H
+#define __ASM_ARM64_BAO_H
+
+#include <linux/arm-smccc.h>
+
+static inline unsigned long bao_ipcshmem_hypercall(unsigned long hypercall_id,
+ unsigned long ipcshmem_id)
+{
+ struct arm_smccc_res res;
+
+ arm_smccc_hvc(ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, ARM_SMCCC_SMC_64,
+ ARM_SMCCC_OWNER_VENDOR_HYP,
+ hypercall_id),
+ ipcshmem_id, 0, 0, 0, 0, 0, 0, &res);
+
+ return res.a0;
+}
+
+#endif /* __ASM_ARM64_BAO_H */
diff --git a/arch/riscv/include/asm/bao.h b/arch/riscv/include/asm/bao.h
new file mode 100644
index 000000000000..35658f37e1bd
--- /dev/null
+++ b/arch/riscv/include/asm/bao.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Bao Hypervisor Hypercall Interface
+ *
+ * Copyright (c) Bao Project and Contributors. All rights reserved.
+ *
+ * Authors:
+ * João Peixoto <joaopeixoto@osyx.tech>
+ * José Martins <jose@osyx.tech>
+ * David Cerdeira <davidmcerdeira@osyx.tech>
+ */
+
+#ifndef __ASM_RISCV_BAO_H
+#define __ASM_RISCV_BAO_H
+
+#include <asm/sbi.h>
+
+#define BAO_SBI_EXT_ID 0x08000ba0
+
+static inline unsigned long bao_ipcshmem_hypercall(unsigned long hypercall_id,
+ unsigned long ipcshmem_id)
+{
+ struct sbiret ret;
+
+ ret = sbi_ecall(BAO_SBI_EXT_ID, hypercall_id, ipcshmem_id, 0, 0, 0, 0,
+ 0);
+
+ return ret.error;
+}
+
+#endif /* __ASM_RISCV_BAO_H */
diff --git a/drivers/virt/Kconfig b/drivers/virt/Kconfig
index 52eb7e4ba71f..cb98c4c52fd1 100644
--- a/drivers/virt/Kconfig
+++ b/drivers/virt/Kconfig
@@ -47,6 +47,8 @@ source "drivers/virt/nitro_enclaves/Kconfig"
source "drivers/virt/acrn/Kconfig"
+source "drivers/virt/bao/Kconfig"
+
endif
source "drivers/virt/coco/Kconfig"
diff --git a/drivers/virt/Makefile b/drivers/virt/Makefile
index f29901bd7820..623a671f8711 100644
--- a/drivers/virt/Makefile
+++ b/drivers/virt/Makefile
@@ -10,3 +10,4 @@ obj-y += vboxguest/
obj-$(CONFIG_NITRO_ENCLAVES) += nitro_enclaves/
obj-$(CONFIG_ACRN_HSM) += acrn/
obj-y += coco/
+obj-$(CONFIG_BAO_SHMEM) += bao/
diff --git a/drivers/virt/bao/Kconfig b/drivers/virt/bao/Kconfig
new file mode 100644
index 000000000000..4f7929d57475
--- /dev/null
+++ b/drivers/virt/bao/Kconfig
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+source "drivers/virt/bao/ipcshmem/Kconfig"
diff --git a/drivers/virt/bao/Makefile b/drivers/virt/bao/Makefile
new file mode 100644
index 000000000000..68f5d3f282c4
--- /dev/null
+++ b/drivers/virt/bao/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_BAO_SHMEM) += ipcshmem/
diff --git a/drivers/virt/bao/ipcshmem/Kconfig b/drivers/virt/bao/ipcshmem/Kconfig
new file mode 100644
index 000000000000..966bb75aa495
--- /dev/null
+++ b/drivers/virt/bao/ipcshmem/Kconfig
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0
+config BAO_SHMEM
+ tristate "Bao hypervisor shared memory support"
+ help
+ This enables support for Bao shared memory communication.
+ It allows the kernel to interface with guests running under
+ the Bao hypervisor, providing a character device interface
+ for exchanging data through dedicated shared-memory regions.
diff --git a/drivers/virt/bao/ipcshmem/Makefile b/drivers/virt/bao/ipcshmem/Makefile
new file mode 100644
index 000000000000..e027dcdb06aa
--- /dev/null
+++ b/drivers/virt/bao/ipcshmem/Makefile
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_BAO_SHMEM) += bao.o
+bao-objs += ipcshmem.o
diff --git a/drivers/virt/bao/ipcshmem/ipcshmem.c b/drivers/virt/bao/ipcshmem/ipcshmem.c
new file mode 100644
index 000000000000..f3892d41248c
--- /dev/null
+++ b/drivers/virt/bao/ipcshmem/ipcshmem.c
@@ -0,0 +1,255 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Bao Hypervisor IPC Through Shared-memory Driver
+ *
+ * Copyright (c) Bao Project and Contributors. All rights reserved.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/miscdevice.h>
+#include <linux/of.h>
+#include <linux/mm.h>
+#include <linux/io.h>
+#include <asm/bao.h>
+
+#define BAO_IPCSHMEM_NAME_LEN 16
+
+/* IPC through shared-memory hypercall ID */
+#define BAO_IPCSHMEM_HYPERCALL_ID 0x1
+
+struct bao_ipcshmem {
+ struct miscdevice miscdev;
+ int id;
+ char label[BAO_IPCSHMEM_NAME_LEN];
+ void *read_base;
+ size_t read_size;
+ void *write_base;
+ size_t write_size;
+ phys_addr_t physical_base;
+ size_t shmem_size;
+ void *shmem_base_addr;
+};
+
+static int bao_ipcshmem_mmap(struct file *filp, struct vm_area_struct *vma)
+{
+ struct bao_ipcshmem *bao = filp->private_data;
+ unsigned long vsize = vma->vm_end - vma->vm_start;
+ unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+ phys_addr_t paddr;
+
+ if (!vsize)
+ return -EINVAL;
+
+ if (offset >= bao->shmem_size ||
+ vsize > bao->shmem_size - offset)
+ return -EINVAL;
+
+ paddr = bao->physical_base + offset;
+
+ if (!PAGE_ALIGNED(paddr))
+ return -EINVAL;
+
+ return remap_pfn_range(vma, vma->vm_start, paddr >> PAGE_SHIFT, vsize,
+ vma->vm_page_prot);
+}
+
+static ssize_t bao_ipcshmem_read(struct file *filp, char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct bao_ipcshmem *bao = filp->private_data;
+ size_t available;
+
+ if (*ppos >= bao->read_size)
+ return 0;
+
+ available = bao->read_size - *ppos;
+ count = min(count, available);
+
+ if (copy_to_user(buf, bao->read_base + *ppos, count))
+ return -EFAULT;
+
+ *ppos += count;
+ return count;
+}
+
+static ssize_t bao_ipcshmem_write(struct file *filp, const char __user *buf,
+ size_t count, loff_t *ppos)
+{
+ struct bao_ipcshmem *bao = filp->private_data;
+ size_t available;
+
+ if (*ppos >= bao->write_size)
+ return 0;
+
+ available = bao->write_size - *ppos;
+ count = min(count, available);
+
+ if (copy_from_user(bao->write_base + *ppos, buf, count))
+ return -EFAULT;
+
+ *ppos += count;
+
+ /* Notify Bao hypervisor */
+ bao_ipcshmem_hypercall(BAO_IPCSHMEM_HYPERCALL_ID, bao->id);
+
+ return count;
+}
+
+static int bao_ipcshmem_open(struct inode *inode, struct file *filp)
+{
+ struct bao_ipcshmem *bao;
+
+ bao = container_of(filp->private_data, struct bao_ipcshmem, miscdev);
+ filp->private_data = bao;
+
+ return 0;
+}
+
+static int bao_ipcshmem_release(struct inode *inode, struct file *filp)
+{
+ filp->private_data = NULL;
+ return 0;
+}
+
+static const struct file_operations bao_ipcshmem_fops = {
+ .owner = THIS_MODULE,
+ .read = bao_ipcshmem_read,
+ .write = bao_ipcshmem_write,
+ .mmap = bao_ipcshmem_mmap,
+ .open = bao_ipcshmem_open,
+ .release = bao_ipcshmem_release,
+};
+
+static int bao_ipcshmem_probe(struct platform_device *pdev)
+{
+ struct device *dev = &pdev->dev;
+ struct device_node *np = dev->of_node;
+ struct resource *r;
+ struct bao_ipcshmem *bao;
+ resource_size_t shmem_size;
+ u32 write_offset;
+ u32 read_offset;
+ u32 write_size;
+ u32 read_size;
+ u32 id;
+ bool rd_in_range;
+ bool wr_in_range;
+ bool disjoint;
+ int ret;
+
+ r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!r) {
+ dev_err(dev, "missing shared memory resource\n");
+ return -ENODEV;
+ }
+
+ ret = of_property_read_u32(np, "id", &id);
+ if (ret) {
+ dev_err(dev, "missing or invalid 'id' property\n");
+ return ret;
+ }
+
+ ret = of_property_read_u32_index(np, "read-channel", 0, &read_offset);
+ if (ret) {
+ dev_err(dev, "failed to read 'read-channel' offset: %d\n", ret);
+ return ret;
+ }
+
+ ret = of_property_read_u32_index(np, "read-channel", 1, &read_size);
+ if (ret) {
+ dev_err(dev, "failed to read 'read-channel' size: %d\n", ret);
+ return ret;
+ }
+
+ ret = of_property_read_u32_index(np, "write-channel", 0, &write_offset);
+ if (ret) {
+ dev_err(dev, "failed to read 'write-channel' offset: %d\n", ret);
+ return ret;
+ }
+
+ ret = of_property_read_u32_index(np, "write-channel", 1, &write_size);
+ if (ret) {
+ dev_err(dev, "failed to read 'write-channel' size: %d\n", ret);
+ return ret;
+ }
+
+ shmem_size = resource_size(r);
+
+ rd_in_range = (read_offset + read_size) <= shmem_size;
+ wr_in_range = (write_offset + write_size) <= shmem_size;
+ disjoint = ((read_offset + read_size) <= write_offset) ||
+ ((write_offset + write_size) <= read_offset);
+
+ if (!rd_in_range || !wr_in_range || !disjoint) {
+ dev_err(dev, "invalid read/write channel ranges\n");
+ return -EINVAL;
+ }
+
+ bao = devm_kzalloc(dev, sizeof(*bao), GFP_KERNEL);
+ if (!bao)
+ return -ENOMEM;
+
+ bao->shmem_base_addr =
+ devm_memremap(dev, r->start, shmem_size, MEMREMAP_WB);
+ if (!bao->shmem_base_addr) {
+ dev_err(dev, "failed to remap shared memory\n");
+ return -ENOMEM;
+ }
+
+ bao->id = id;
+ bao->read_size = read_size;
+ bao->write_size = write_size;
+ bao->read_base = (u8 *)bao->shmem_base_addr + read_offset;
+ bao->write_base = (u8 *)bao->shmem_base_addr + write_offset;
+ bao->physical_base = r->start;
+ bao->shmem_size = shmem_size;
+
+ scnprintf(bao->label, BAO_IPCSHMEM_NAME_LEN, "baoipc%d", id);
+
+ bao->miscdev.minor = MISC_DYNAMIC_MINOR;
+ bao->miscdev.name = bao->label;
+ bao->miscdev.fops = &bao_ipcshmem_fops;
+ bao->miscdev.parent = dev;
+
+ ret = misc_register(&bao->miscdev);
+ if (ret) {
+ dev_err(dev, "failed to register misc device: %d\n", ret);
+ return ret;
+ }
+
+ platform_set_drvdata(pdev, bao);
+
+ dev_info(dev, "Bao IPC shared memory device '%s' registered\n", bao->label);
+ return 0;
+}
+
+static void bao_ipcshmem_remove(struct platform_device *pdev)
+{
+ struct bao_ipcshmem *bao = platform_get_drvdata(pdev);
+
+ if (bao)
+ misc_deregister(&bao->miscdev);
+}
+
+static const struct of_device_id of_bao_ipcshmem_match[] = {
+ { .compatible = "bao,ipcshmem" },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, of_bao_ipcshmem_match);
+
+static struct platform_driver bao_ipcshmem_driver = {
+ .probe = bao_ipcshmem_probe,
+ .remove = bao_ipcshmem_remove,
+ .driver = {
+ .name = "baoipc",
+ .of_match_table = of_bao_ipcshmem_match,
+ },
+};
+
+module_platform_driver(bao_ipcshmem_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("David Cerdeira <davidmcerdeira@osyx.tech>");
+MODULE_AUTHOR("José Martins <jose@osyx.tech>");
+MODULE_AUTHOR("João Peixoto <joaopeixoto@osyx.tech>");
+MODULE_DESCRIPTION("Bao Hypervisor IPC Through Shared-memory Driver");
--
2.43.0
next prev parent reply other threads:[~2026-01-07 16:29 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-24 13:52 [PATCH 0/5] virt: Add Bao hypervisor IPC and I/O dispatcher drivers joaopeixoto
2025-12-24 13:52 ` [PATCH 1/5] dt-bindings: Add Bao IPC shared memory driver binding joaopeixoto
2025-12-24 16:18 ` Rob Herring (Arm)
2025-12-25 8:57 ` Krzysztof Kozlowski
2025-12-24 13:52 ` [PATCH 2/5] virt: add Bao IPC shared memory driver joaopeixoto
2025-12-24 15:53 ` Greg KH
2025-12-24 15:54 ` Greg KH
2025-12-25 9:02 ` Krzysztof Kozlowski
2025-12-24 13:52 ` [PATCH 3/5] dt-bindings: Add Bao I/O dispatcher driver binding joaopeixoto
2025-12-24 16:18 ` Rob Herring (Arm)
2025-12-25 8:58 ` Krzysztof Kozlowski
2025-12-24 13:52 ` [PATCH 5/5] MAINTAINERS: Add entries for Bao hypervisor drivers, headers, and DT bindings joaopeixoto
2025-12-25 8:52 ` Krzysztof Kozlowski
2025-12-25 8:51 ` [PATCH 0/5] virt: Add Bao hypervisor IPC and I/O dispatcher drivers Krzysztof Kozlowski
[not found] ` <20251224135217.25350-5-joaopeixoto@osyx.tech>
2025-12-25 9:12 ` [PATCH 4/5] virt: add Bao I/O dispatcher driver Krzysztof Kozlowski
2026-01-07 16:28 ` [PATCH v2 0/6] virt: Add Bao hypervisor IPC and I/O dispatcher drivers joaopeixoto
2026-01-07 16:28 ` [PATCH 1/6] dt-bindings: Add Bao IPC shared memory driver binding joaopeixoto
2026-01-07 16:46 ` Krzysztof Kozlowski
2026-01-07 16:28 ` joaopeixoto [this message]
2026-01-07 18:54 ` [PATCH 2/6] virt: bao: Add Bao IPC shared memory driver Randy Dunlap
2026-01-14 20:37 ` Andrew Jones
2026-01-07 16:28 ` [PATCH 3/6] dt-bindings: Add Bao I/O dispatcher driver binding joaopeixoto
2026-01-07 16:47 ` Krzysztof Kozlowski
2026-01-07 16:28 ` [PATCH 4/6] virt: bao: Add Bao I/O dispatcher driver joaopeixoto
2026-01-14 20:32 ` Andrew Jones
2026-01-07 16:28 ` [PATCH 5/6] virt: bao: Move BAO_IPCSHMEM_HYPERCALL_ID to common header joaopeixoto
2026-01-07 19:36 ` Greg KH
2026-01-14 20:34 ` Andrew Jones
2026-01-07 16:28 ` [PATCH 6/6] MAINTAINERS: Add entries for Bao hypervisor drivers, headers, and DT bindings joaopeixoto
2026-01-07 19:37 ` [PATCH v2 0/6] virt: Add Bao hypervisor IPC and I/O dispatcher drivers Greg KH
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=20260107162829.416885-3-joaopeixoto@osyx.tech \
--to=joaopeixoto@osyx.tech \
--cc=ajd@linux.ibm.com \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=bagasdotme@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=dan.j.williams@intel.com \
--cc=davidmcerdeira@osyx.tech \
--cc=dev@kael-k.io \
--cc=devicetree@vger.kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=haren@linux.ibm.com \
--cc=heiko@sntech.de \
--cc=jose@osyx.tech \
--cc=kever.yang@rock-chips.com \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=maddy@linux.ibm.com \
--cc=mani@kernel.org \
--cc=nathan@kernel.org \
--cc=neil.armstrong@linaro.org \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=robh@kernel.org \
--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