Skip to content

Commit

Permalink
recipes-kernel: linux: add support for Xen
Browse files Browse the repository at this point in the history
This patch adds support to enable Xen for ti-linux-staging. This
involves a kernel fragment specifying desired defconfig options as well
as two patches:

fix-rpmsg-xen.patch: This patch fixes the rpmsg_probe failure that
happens otherwise.

drivers-...-protocol.patch: This patch [1] is required for compatibility
with a patchset [2] for xen which fixes init-dom0less and hotplugging
for dom0less domains.

[1]: https://lore.kernel.org/xen-devel/[email protected]/
[2]: https://lore.kernel.org/all/alpine.DEB.2.22.394.2405241552240.2557291@ubuntu-linux-20-04-desktop/

Signed-off-by: Amneesh Singh <[email protected]>
  • Loading branch information
natto1784 committed Sep 13, 2024
1 parent 3690d83 commit a235ef3
Show file tree
Hide file tree
Showing 6 changed files with 197 additions and 1 deletion.
9 changes: 9 additions & 0 deletions recipes-kernel/linux/linux-ti-enable-xen.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FILESEXTRAPATHS:prepend := "${THISDIR}/xen:"

SRC_URI:append = " \
file://drivers-xen-improve-the-late-xenstore-init-protocol.patch \
file://fix-rpmsg-xen.patch \
file://xen.cfg \
"

KERNEL_CONFIG_FRAGMENTS:append = " ${WORKDIR}/xen.cfg"
2 changes: 2 additions & 0 deletions recipes-kernel/linux/linux-ti-staging-rt_%.bbappend
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
SRCREV:tie-jailhouse = "782a2e18a2af099d5c53bc4ba9f59d24a0ce8467"

include ${@bb.utils.contains('DISTRO_FEATURES', 'xen', 'linux-ti-enable-xen.inc', '', d)}

PR:append = "_tisdk_8"

3 changes: 2 additions & 1 deletion recipes-kernel/linux/linux-ti-staging_%.bbappend
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
SRCREV:tie-jailhouse = "c76373e447c96b32fe08beceef7a499d16eaed96"

PR:append = "_tisdk_5"
include ${@bb.utils.contains('DISTRO_FEATURES', 'xen', 'linux-ti-enable-xen.inc', '', d)}

PR:append = "_tisdk_5"
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
Subject: [PATCH v2] drivers/xen: Improve the late XenStore init

Currently, the late XenStore init protocol is only triggered properly
for the case that HVM_PARAM_STORE_PFN is ~0ULL (invalid). For the
case that XenStore interface is allocated but not ready (the connection
status is not XENSTORE_CONNECTED), Linux should also wait until the
XenStore is set up properly.

Introduce a macro to describe the XenStore interface is ready, use
it in xenbus_probe_initcall() to select the code path of doing the
late XenStore init protocol or not. Since now we have more than one
condition for XenStore late init, rework the check in xenbus_probe()
for the free_irq().

Take the opportunity to enhance the check of the allocated XenStore
interface can be properly mapped, and return error early if the
memremap() fails.

Fixes: 5b3353949e89 ("xen: add support for initializing xenstore later as HVM domain")
Signed-off-by: Henry Wang <[email protected]>
Signed-off-by: Michal Orzel <[email protected]>
---
v2:
- Use -EINVAL for the memremap() check. (Stefano)
- Add Fixes: tag. (Stefano)
- Rework the condition for free_irq() in xenbus_probe(). (Stefano)
---
drivers/xen/xenbus/xenbus_probe.c | 36 ++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 13 deletions(-)

diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index 3205e5d724c8..1a9ded0cddcb 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -65,13 +65,17 @@
#include "xenbus.h"


-static int xs_init_irq;
+static int xs_init_irq = -1;
int xen_store_evtchn;
EXPORT_SYMBOL_GPL(xen_store_evtchn);

struct xenstore_domain_interface *xen_store_interface;
EXPORT_SYMBOL_GPL(xen_store_interface);

+#define XS_INTERFACE_READY \
+ ((xen_store_interface != NULL) && \
+ (xen_store_interface->connection == XENSTORE_CONNECTED))
+
enum xenstore_init xen_store_domain_type;
EXPORT_SYMBOL_GPL(xen_store_domain_type);

@@ -751,19 +755,19 @@ static void xenbus_probe(void)
{
xenstored_ready = 1;

- if (!xen_store_interface) {
+ if (!xen_store_interface)
xen_store_interface = memremap(xen_store_gfn << XEN_PAGE_SHIFT,
XEN_PAGE_SIZE, MEMREMAP_WB);
- /*
- * Now it is safe to free the IRQ used for xenstore late
- * initialization. No need to unbind: it is about to be
- * bound again from xb_init_comms. Note that calling
- * unbind_from_irqhandler now would result in xen_evtchn_close()
- * being called and the event channel not being enabled again
- * afterwards, resulting in missed event notifications.
- */
+ /*
+ * Now it is safe to free the IRQ used for xenstore late
+ * initialization. No need to unbind: it is about to be
+ * bound again from xb_init_comms. Note that calling
+ * unbind_from_irqhandler now would result in xen_evtchn_close()
+ * being called and the event channel not being enabled again
+ * afterwards, resulting in missed event notifications.
+ */
+ if (xs_init_irq >= 0)
free_irq(xs_init_irq, &xb_waitq);
- }

/*
* In the HVM case, xenbus_init() deferred its call to
@@ -822,7 +826,7 @@ static int __init xenbus_probe_initcall(void)
if (xen_store_domain_type == XS_PV ||
(xen_store_domain_type == XS_HVM &&
!xs_hvm_defer_init_for_callback() &&
- xen_store_interface != NULL))
+ XS_INTERFACE_READY))
xenbus_probe();

/*
@@ -831,7 +835,7 @@ static int __init xenbus_probe_initcall(void)
* started, then probe. It will be triggered when communication
* starts happening, by waiting on xb_waitq.
*/
- if (xen_store_domain_type == XS_LOCAL || xen_store_interface == NULL) {
+ if (xen_store_domain_type == XS_LOCAL || !XS_INTERFACE_READY) {
struct task_struct *probe_task;

probe_task = kthread_run(xenbus_probe_thread, NULL,
@@ -1014,6 +1018,12 @@ static int __init xenbus_init(void)
xen_store_interface =
memremap(xen_store_gfn << XEN_PAGE_SHIFT,
XEN_PAGE_SIZE, MEMREMAP_WB);
+ if (!xen_store_interface) {
+ pr_err("%s: cannot map HVM_PARAM_STORE_PFN=%llx\n",
+ __func__, v);
+ err = -EINVAL;
+ goto out_error;
+ }
if (xen_store_interface->connection != XENSTORE_CONNECTED)
wait = true;
}
--
2.34.1
13 changes: 13 additions & 0 deletions recipes-kernel/linux/xen/fix-rpmsg-xen.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 7d320f799ca1..96ba831cf73f 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -279,7 +279,7 @@ static bool vring_use_dma_api(struct virtio_device *vdev)
* the DMA API if we're a Xen guest, which at least allows
* all of the sensible Xen configurations to work correctly.
*/
- if (xen_domain())
+ if (xen_pv_domain())
return true;

return false;
55 changes: 55 additions & 0 deletions recipes-kernel/linux/xen/xen.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# Xen Options
#
CONFIG_XEN=y
CONFIG_XEN_DOM0=y
CONFIG_MMU_NOTIFIER=y
CONFIG_HIBERNATE_CALLBACKS=y
CONFIG_SYS_HYPERVISOR=y
CONFIG_XEN_BLKDEV_FRONTEND=y
CONFIG_XEN_BLKDEV_BACKEND=y
CONFIG_XEN_SCSI_FRONTEND=y
CONFIG_XEN_NETDEV_FRONTEND=y
CONFIG_XEN_NETDEV_BACKEND=y
CONFIG_INPUT_MISC=y
CONFIG_INPUT_XEN_KBDDEV_FRONTEND=y
CONFIG_HVC_IRQ=y
CONFIG_HVC_XEN=y
CONFIG_HVC_XEN_FRONTEND=y
CONFIG_XEN_WDT=m
CONFIG_FB_SYS_FILLRECT=y
CONFIG_FB_SYS_COPYAREA=y
CONFIG_FB_SYS_IMAGEBLIT=y
CONFIG_FB_SYS_FOPS=y
CONFIG_FB_DEFERRED_IO=y
CONFIG_XEN_FBDEV_FRONTEND=y
CONFIG_XEN_BALLOON=y
CONFIG_XEN_BALLOON_MEMORY_HOTPLUG=y
CONFIG_XEN_SCRUB_PAGES_DEFAULT=y
CONFIG_XEN_DEV_EVTCHN=y
CONFIG_XEN_BACKEND=y
CONFIG_XENFS=y
CONFIG_XEN_COMPAT_XENFS=y
CONFIG_XEN_SYS_HYPERVISOR=y
CONFIG_XEN_XENBUS_FRONTEND=y
CONFIG_XEN_GNTDEV=y
CONFIG_XEN_GNTDEV_DMABUF=y
CONFIG_XEN_GRANT_DEV_ALLOC=y
CONFIG_XEN_GRANT_DMA_ALLOC=y
CONFIG_SWIOTLB_XEN=y
CONFIG_XEN_PRIVCMD=y
CONFIG_DRM_XEN=y
CONFIG_DRM_XEN_FRONTEND=y

#
# PL011 support
#
CONFIG_SERIAL_AMBA_PL011=y
CONFIG_SERIAL_AMBA_PL011_CONSOLE=y

#
# Userspace IO Options
#
CONFIG_UIO=y
CONFIG_UIO_CIF=y
CONFIG_UIO_PDRV_GENIRQ=y

0 comments on commit a235ef3

Please sign in to comment.