[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC 29/38] x86/hyperlaunch: allocate console for domu


  • To: xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Date: Sat, 19 Apr 2025 18:08:11 -0400
  • Arc-authentication-results: i=1; mx.zohomail.com; dkim=pass header.i=apertussolutions.com; spf=pass smtp.mailfrom=dpsmith@xxxxxxxxxxxxxxxxxxxx; dmarc=pass header.from=<dpsmith@xxxxxxxxxxxxxxxxxxxx>
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1745100556; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=OMaTtguVsoafCK0lkNIJcl8+/3XaPHmXDwj/NHsEKbc=; b=Hws8dTO1HmPHgoq6VRIpLLm1V3Swu8XS2TR3Zvv8RSHVkoocqdM1HXimczkcegYwG1F5yCkeDgiJyt4P1QbltD2H57Du44+wWBYRHj2ngi7kjeAH9hNB0mdbw5XsSkLYEnBRjTnR8rGouh52lpyh8mw5InyG/QnG0k5Qz6qJjSI=
  • Arc-seal: i=1; a=rsa-sha256; t=1745100556; cv=none; d=zohomail.com; s=zohoarc; b=QzgX0Y8mWmsz+AsIiWp0nfAjtW0zaD5vB/KouKf3Hf/K464Etr0B32nW8ChHLUIXQ+gkP7ESDKwHvCoZ4O4QYeFQFLiKRdsXaS2sZQVrEE1Rc6nS5dsdlYzeP35AuPHLK/+A2tB4ejwEyjck6P6gkwdogo5qxn1crJLU2Tq7Pe8=
  • Cc: "Daniel P. Smith" <dpsmith@xxxxxxxxxxxxxxxxxxxx>, jason.andryuk@xxxxxxx, stefano.stabellini@xxxxxxx, agarciav@xxxxxxx, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Sat, 19 Apr 2025 22:20:50 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

During domU construction, a page of memory and an event channel must be setup
for the console connection. In this commit, a page from the special page region
of domU is setup as the console page along with an event channel. The page
address and event channel are published in the HVM parameters, so they may be
published in Xenstore once it is online.

Signed-off-by: Daniel P. Smith <dpsmith@xxxxxxxxxxxxxxxxxxxx>
---
 xen/arch/x86/domain-builder/domain.c   | 56 ++++++++++++++++++++++++++
 xen/arch/x86/hvm/dom_build.c           | 34 ++++++++++++++++
 xen/arch/x86/include/asm/boot-domain.h |  7 ++++
 3 files changed, 97 insertions(+)

diff --git a/xen/arch/x86/domain-builder/domain.c 
b/xen/arch/x86/domain-builder/domain.c
index c1b2e011aaa0..7ce069a57c5d 100644
--- a/xen/arch/x86/domain-builder/domain.c
+++ b/xen/arch/x86/domain-builder/domain.c
@@ -6,6 +6,7 @@
 #include <xen/cpumask.h>
 #include <xen/domain.h>
 #include <xen/err.h>
+#include <xen/event.h>
 #include <xen/grant_table.h>
 #include <xen/init.h>
 #include <xen/libelf.h>
@@ -187,6 +188,58 @@ void __init alloc_dom_vcpus(struct domain *d)
     domain_update_node_affinity(d);
 }
 
+static int __init alloc_dom_evtchn(
+    const struct boot_domain *d, const struct boot_domain *r,
+    evtchn_alloc_unbound_t *ec)
+{
+    int rc;
+
+    ec->dom = d->domid;
+    ec->remote_dom = r->domid;
+
+    rc = evtchn_alloc_unbound(ec, 0);
+    if ( rc )
+    {
+        printk(XENLOG_WARNING "Failed allocating event channel for %pd\n",
+               d->d);
+        return rc;
+    }
+
+    return 0;
+}
+
+static int __init alloc_console_evtchn(
+    const struct boot_info *bi, struct boot_domain *bd)
+{
+    evtchn_alloc_unbound_t evtchn_req;
+    const struct boot_domain *hwdom;
+    int idx, rc;
+
+    idx = first_boot_domain_index(bi, BUILD_CAPS_HARDWARE);
+    if ( idx < 0 )
+    {
+        printk(XENLOG_WARNING "No backing hardware domain for %pd console\n",
+               bd->d);
+        return -EINVAL;
+    }
+
+    if ( bi->domains[idx].d )
+        hwdom = &bi->domains[idx];
+    else
+    {
+        printk(XENLOG_WARNING "Hardware domain for %pd console not 
constructed\n",
+               bd->d);
+        return -EINVAL;
+    }
+
+    if ( (rc = alloc_dom_evtchn(bd, hwdom, &evtchn_req)) < 0 )
+        return rc;
+
+    bd->console.evtchn = evtchn_req.port;
+
+    return 0;
+}
+
 static size_t __init domain_cmdline_size(
     struct boot_info *bi, struct boot_domain *bd)
 {
@@ -309,6 +362,9 @@ struct domain *__init arch_create_dom(
         bd->cmdline = cmdline;
     }
 
+   if ( !(bd->capabilities & BUILD_CAPS_HARDWARE) )
+       alloc_console_evtchn(bi, bd);
+
     if ( construct_dom0(bd) != 0 )
         panic("Could not construct domain 0\n");
 
diff --git a/xen/arch/x86/hvm/dom_build.c b/xen/arch/x86/hvm/dom_build.c
index c482d5c2d974..934ae138e58f 100644
--- a/xen/arch/x86/hvm/dom_build.c
+++ b/xen/arch/x86/hvm/dom_build.c
@@ -9,6 +9,7 @@
  */
 
 #include <xen/acpi.h>
+#include <xen/event.h>
 #include <xen/iommu.h>
 #include <xen/init.h>
 #include <xen/softirq.h>
@@ -19,6 +20,7 @@
 #include <public/arch-x86/hvm/start_info.h>
 #include <public/hvm/e820.h>
 #include <public/hvm/hvm_vcpu.h>
+#include <public/hvm/params.h>
 
 #include <asm/bootinfo.h>
 #include <asm/bzimage.h>
@@ -899,6 +901,35 @@ static int __init pvh_load_kernel(
     return 0;
 }
 
+static int __init alloc_console_page(struct boot_domain *bd)
+{
+    paddr_t con_addr = special_pfn(SPECIALPAGE_CONSOLE) << PAGE_SHIFT;
+    uint32_t fields[4] = { 0 };
+
+    if ( !port_is_valid(bd->d, bd->console.evtchn) )
+    {
+        printk("No event channel available for %pd console\n", bd->d);
+        return -EINVAL;
+    }
+
+    /*
+     * Clear the xencons_interface fields that are located after a 1024 rx and
+     * a 2048 tx buffer, 3072 bytes.
+     */
+    if ( hvm_copy_to_guest_phys(con_addr + 3072, fields, sizeof(fields),
+                                bd->d->vcpu[0]) )
+    {
+        printk("Unable to set xenstore connection state\n");
+        return -EFAULT;
+    }
+
+    bd->console.gfn = PFN_DOWN(con_addr);
+    bd->d->arch.hvm.params[HVM_PARAM_CONSOLE_PFN] = bd->console.gfn;
+    bd->d->arch.hvm.params[HVM_PARAM_CONSOLE_EVTCHN] = bd->console.evtchn;
+
+    return 0;
+}
+
 int __init dom_construct_pvh(struct boot_domain *bd)
 {
     paddr_t entry, start_info;
@@ -975,6 +1006,9 @@ int __init dom_construct_pvh(struct boot_domain *bd)
         return rc;
     }
 
+    if ( !is_hardware_domain(bd->d) )
+        alloc_console_page(bd);
+
     if ( opt_dom0_verbose )
     {
         printk("Dom%u memory map:\n", bd->domid);
diff --git a/xen/arch/x86/include/asm/boot-domain.h 
b/xen/arch/x86/include/asm/boot-domain.h
index 32f1f8fbc4e8..cb6e1fab23ba 100644
--- a/xen/arch/x86/include/asm/boot-domain.h
+++ b/xen/arch/x86/include/asm/boot-domain.h
@@ -5,6 +5,9 @@
  * Copyright (c) 2024 Christopher Clark <christopher.w.clark@xxxxxxxxx>
  */
 
+#include <public/xen.h>
+#include <public/event_channel.h>
+
 #ifndef __XEN_X86_BOOTDOMAIN_H__
 #define __XEN_X86_BOOTDOMAIN_H__
 
@@ -35,6 +38,10 @@ struct boot_domain {
     const char *cmdline;
 
     struct domain *d;
+    struct {
+        xen_pfn_t gfn;
+        evtchn_port_t evtchn;
+    } console;
 };
 
 #endif
-- 
2.30.2




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.