xenconsole: Add connection flag
v2 cover xenconsole: Add connection flag
Add a connection flag to the console interface page so a domain can tell if it is connected or not. This became a series in v2 to add flag setting to libxenguest.
Jason Andryuk (3):
xenconsole: Add connection flag libs/guest: Set console page to disconnected libs/guest: Set console as disconnected on resume
tools/console/daemon/io.c | 4 +++ tools/include/xenguest.h | 4 +++ tools/libs/guest/xg_dom_arm.c | 2 +- tools/libs/guest/xg_dom_boot.c | 36 ++++++++++++++++++++++++ tools/libs/guest/xg_dom_x86.c | 6 ++-- tools/libs/guest/xg_sr_restore_x86_hvm.c | 2 +- tools/libs/guest/xg_sr_restore_x86_pv.c | 1 + xen/include/public/io/console.h | 13 +++++++++ 8 files changed, 63 insertions(+), 5 deletions(-)
Signature · 1 line
2.50.1
PATCH v2 1/3 xenconsole: Add connection flag
With hyperlaunch, a domU can start before its console ring is connected by xenconsoled. With nothing emptying the ring, it can quickly fill during boot. In domU_write_console(), __write_console() returns 0 when the ring is full. This loops spins until xenconsoled starts emptying the ring:
while (len) {
ssize_t sent = __write_console(cons, data, len);
if (sent < 0)
return sent;
data += sent;
len -= sent;
if (unlikely(len))
HYPERVISOR_sched_op(SCHEDOP_yield, NULL);
}The goal of this patch is to add a way for the frontend to know when a console is connected. This patch adds a new flag to the end of the console ring structure. It is used for the backend to indicate that it has connected and started servicing the page.
The two values areXENCONSOLE_DISCONNECTED 1XENCONSOLE_CONNECTED 0
XENCONSOLE_DISCONNECTED indicates to the guest that ring is disconnected, so it will not be serviced. The guest can avoid writing into it in that case. A domU can use console hypercalls and only transition to the ring when it is connected and won't fill and block.
Once the backend (xenconsoled) maps and starts servicing the console, the flag will be set to XENCONSOLE_CONNECTED (0) to indicate the backend state to the frontend.
The connected value as 0 will be match the default of a zero-ed console page. Hyperlaunch can set the flag to XENCONSOLE_DISCONNECTED and let xenconsoled set to XENCONSOLE_CONNECTED.
Old domU hvc_xen drivers won't check the flag.
New domU hvc_xen running on a new xen/xenconsoled will work properly. New domU hvc_xen on old xen/xenconsoled should only see a 0 for the flag and behave as if connected.
---
v2:
Rename "connection"
Use uint8_t
v1:
Remove evtchn notify call
Set connected later when there is no error
RFC v3:
Flip flag values so 0 is connected.
The other option would be to add:uint32_t featuresuint32_t connected
New domUs would check features for a magic value and/or flag to know they can rely on connected transitioning.
I think making XENCONSOLE_CONNECTED == 0 side steps the need for an additional features field. As long as assuming zero-ed memory is acceptable. However, this only matters for a hyperlaunched guest - xenconsoled will normally readily connect the console and set the value.
This assumes that existing frontends are not using the flag space for some other use.
--- tools/console/daemon/io.c | 4 ++++ xen/include/public/io/console.h | 13 +++++++++++++ 2 files changed, 17 insertions(+)
tools/console/daemon/io.c +4 -0
@@ -781,6 +781,10 @@ static int console_create_ring(struct console *con) con->log_fd =create_console_log (con); out: +/* Mark the console connected. */ +if (!err && con->interface) + con->interface->connection =XENCONSOLE_CONNECTED ; +return err; }
xen/include/public/io/console.h +13 -0
@@ -19,6 +19,19 @@ struct xencons_interface {char out[2048 ];XENCONS_RING_IDX in_cons, in_prod;XENCONS_RING_IDX out_cons, out_prod; +/* +* Flag values signaling from backend to frontend whether the console is +* connected. i.e. Whether it will be serviced and emptied. +* +* The flag starts as disconnected. +*/ +#define XENCONSOLE_DISCONNECTED 1 +/* +* The flag is set to connected when the backend connects and the console +* will be serviced. +*/ +#define XENCONSOLE_CONNECTED 0 +uint8_t connection; };#ifdef XEN_WANT_FLEX_CONSOLE_RING
Signature · 1 line
2.50.1
PATCH v2 2/3 libs/guest: Set console page to disconnected
In reply to Jason AndryukInitialize xencons_interface's connection field to XENCONSOLE_DISCONNECTED. xenconsoled will mark the page as connected when it establishes the connection.
---xc_dom_console_init() seems closer to the functionality of the gnttab functions, so I put it in xg_dom_boot.c. It can't take a struct xc_dom_image pointer when used with save/restore.
v2:
New
--- tools/include/xenguest.h | 2 ++ tools/libs/guest/xg_dom_arm.c | 2 +- tools/libs/guest/xg_dom_boot.c | 20 ++++++++++++++++++++ tools/libs/guest/xg_dom_x86.c | 6 +++--- 4 files changed, 26 insertions(+), 4 deletions(-)
tools/include/xenguest.h +2 -0
@@ -335,6 +335,8 @@ void *xc_dom_boot_domU_map(struct xc_dom_image *dom, xen_pfn_t pfn, xen_pfn_t count);int xc_dom_boot_image (struct xc_dom_image *dom);int xc_dom_compat_check (struct xc_dom_image *dom); +int xc_dom_console_init (xc_interface *xch,uint32_t guest_domid, +xen_pfn_t console_gfn);int xc_dom_gnttab_init (struct xc_dom_image *dom); int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid, bool is_hvm,
tools/libs/guest/xg_dom_arm.c +1 -1
@@ -70,7 +70,7 @@ static int alloc_magic_pages(struct xc_dom_image *dom) dom->xenstore_pfn = base +XENSTORE_PFN_OFFSET ; dom->vuart_gfn = base +VUART_PFN_OFFSET ; -xc_clear_domain_page (dom->xch, dom->guest_domid, dom->console_pfn); +xc_dom_console_init (dom->xch, dom->guest_domid, dom->console_pfn);xc_clear_domain_page (dom->xch, dom->guest_domid, dom->xenstore_pfn);xc_clear_domain_page (dom->xch, dom->guest_domid, base +MEMACCESS_PFN_OFFSET );xc_clear_domain_page (dom->xch, dom->guest_domid, dom->vuart_gfn);
tools/libs/guest/xg_dom_boot.c +20 -0
@@ -34,6 +34,7 @@#include "xg_core.h" #include <xen/hvm/params.h> #include <xen/grant_table.h> +#include <xen/io/console.h> /* ------------------------------------------------------------------------ */
@@ -427,6 +428,25 @@ int xc_dom_gnttab_init(struct xc_dom_image *dom) dom->console_domid, dom->xenstore_domid); } +int xc_dom_console_init (xc_interface *xch, +uint32_t domid, +unsigned long dst_pfn) +{ +const size_t size =PAGE_SIZE ; +struct xencons_interface *xencons =xc_map_foreign_range ( + xch, domid, size,PROT_WRITE , dst_pfn); + +if ( xencons ==NULL ) +return -1 ; + +memset (xencons,0 , size); + xencons->connection =XENCONSOLE_DISCONNECTED ; + +munmap (xencons, size); +xc_domain_cacheflush (xch, domid, dst_pfn,1 ); +return 0 ; +} +/* * Local variables: * mode: C
tools/libs/guest/xg_dom_x86.c +3 -3
@@ -587,8 +587,8 @@ static int alloc_magic_pages_pv(struct xc_dom_image *dom) dom->console_pfn =xc_dom_alloc_page (dom,"console" );if ( dom->console_pfn ==INVALID_PFN )return -1 ; -xc_clear_domain_page (dom->xch, dom->guest_domid, -xc_dom_p2m (dom, dom->console_pfn)); +xc_dom_console_init (dom->xch, dom->guest_domid, +xc_dom_p2m (dom, dom->console_pfn)); dom->alloc_bootstack =1 ;
@@ -734,7 +734,7 @@ static int alloc_magic_pages_hvm(struct xc_dom_image *dom) special_pfn(SPECIALPAGE_IDENT_PT) << PAGE_SHIFT); dom->console_pfn =special_pfn (SPECIALPAGE_CONSOLE ); -xc_clear_domain_page (dom->xch, dom->guest_domid, dom->console_pfn); +xc_dom_console_init (dom->xch, dom->guest_domid, dom->console_pfn); dom->xenstore_pfn =special_pfn (SPECIALPAGE_XENSTORE );xc_clear_domain_page (dom->xch, dom->guest_domid, dom->xenstore_pfn);
Signature · 1 line
2.50.1
PATCH v2 3/3 libs/guest: Set console as disconnected on resume
In reply to Jason AndryukThere is currently an asymmetry between HVM where the page is cleared and PV where the contents are restored.
Add xc_dom_console_set_disconnected() to only set the connection flag for PV guests.
xenconsoled is responsible for setting the console connected when it attaches.
---
v2:
New
--- tools/include/xenguest.h | 2 ++ tools/libs/guest/xg_dom_boot.c | 24 ++++++++++++++++++++---- tools/libs/guest/xg_sr_restore_x86_hvm.c | 2 +- tools/libs/guest/xg_sr_restore_x86_pv.c | 1 + 4 files changed, 24 insertions(+), 5 deletions(-)
tools/include/xenguest.h +2 -0
@@ -337,6 +337,8 @@ int xc_dom_boot_image(struct xc_dom_image *dom);int xc_dom_compat_check (struct xc_dom_image *dom);int xc_dom_console_init (xc_interface *xch,uint32_t guest_domid,xen_pfn_t console_gfn); +int xc_dom_console_set_disconnected (xc_interface *xch,uint32_t guest_domid, +xen_pfn_t console_gfn);int xc_dom_gnttab_init (struct xc_dom_image *dom); int xc_dom_gnttab_seed(xc_interface *xch, uint32_t guest_domid, bool is_hvm,
tools/libs/guest/xg_dom_boot.c +20 -4
@@ -428,9 +428,10 @@ int xc_dom_gnttab_init(struct xc_dom_image *dom) dom->console_domid, dom->xenstore_domid); } -int xc_dom_console_init (xc_interface *xch, -uint32_t domid, -unsigned long dst_pfn) +static int dom_console_init (xc_interface *xch, +uint32_t domid, +unsigned long dst_pfn, +bool clear) {const size_t size =PAGE_SIZE ; struct xencons_interface *xencons = xc_map_foreign_range(
@@ -439,7 +440,8 @@ int xc_dom_console_init(xc_interface *xch,if ( xencons ==NULL )return -1 ; -memset (xencons,0 , size); +if (clear) +memset (xencons,0 , size); xencons->connection =XENCONSOLE_DISCONNECTED ;munmap (xencons, size);
@@ -447,6 +449,20 @@ int xc_dom_console_init(xc_interface *xch,return 0 ; } +int xc_dom_console_init (xc_interface *xch, +uint32_t domid, +unsigned long dst_pfn) +{ +return dom_console_init (xch, domid, dst_pfn, true); +} + +int xc_dom_console_set_disconnected (xc_interface *xch, +uint32_t domid, +unsigned long dst_pfn) +{ +return dom_console_init (xch, domid, dst_pfn, false); +} +/* * Local variables: * mode: C
tools/libs/guest/xg_sr_restore_x86_hvm.c +1 -1
@@ -62,7 +62,7 @@ static int handle_hvm_params(struct xc_sr_context *ctx, {case HVM_PARAM_CONSOLE_PFN : ctx->restore.console_gfn = entry->value; -xc_clear_domain_page (xch, ctx->domid, entry->value); +xc_dom_console_init (xch, ctx->domid, entry->value);break ;case HVM_PARAM_STORE_PFN : ctx->restore.xenstore_gfn = entry->value;
tools/libs/guest/xg_sr_restore_x86_pv.c +1 -0
@@ -208,6 +208,7 @@ static int process_start_info(struct xc_sr_context *ctx, goto err; } +xc_dom_console_set_disconnected (xch, ctx->domid, mfn); ctx->restore.console_gfn = mfn;SET_FIELD (guest_start_info, console.domU.mfn, mfn, ctx->x86.pv.width); SET_FIELD(guest_start_info, console.domU.evtchn,
Signature · 1 line
2.50.1
Quoted 9 lines · Jason Andryuk
Add a connection flag to the console interface page so a domain can tell if it is connected or not. This became a series in v2 to add flag setting to libxenguest.
Jason Andryuk (3):
xenconsole: Add connection flag libs/guest: Set console page to disconnected libs/guest: Set console as disconnected on resume
Quoted 10 lines
tools/console/daemon/io.c | 4 +++ tools/include/xenguest.h | 4 +++ tools/libs/guest/xg_dom_arm.c | 2 +- tools/libs/guest/xg_dom_boot.c | 36 ++++++++++++++++++++++++ tools/libs/guest/xg_dom_x86.c | 6 ++-- tools/libs/guest/xg_sr_restore_x86_hvm.c | 2 +- tools/libs/guest/xg_sr_restore_x86_pv.c | 1 + xen/include/public/io/console.h | 13 +++++++++ 8 files changed, 63 insertions(+), 5 deletions(-)
For the series:
Juergen
Anthony PERARD
Acked-byQuoted 21 lines · Jürgen Groß
Quoted 9 lines · Jason Andryuk
Add a connection flag to the console interface page so a domain can tell if it is connected or not. This became a series in v2 to add flag setting to libxenguest.
Jason Andryuk (3):
xenconsole: Add connection flag libs/guest: Set console page to disconnected libs/guest: Set console as disconnected on resumeQuoted 10 lines
tools/console/daemon/io.c | 4 +++ tools/include/xenguest.h | 4 +++ tools/libs/guest/xg_dom_arm.c | 2 +- tools/libs/guest/xg_dom_boot.c | 36 ++++++++++++++++++++++++ tools/libs/guest/xg_dom_x86.c | 6 ++-- tools/libs/guest/xg_sr_restore_x86_hvm.c | 2 +- tools/libs/guest/xg_sr_restore_x86_pv.c | 1 + xen/include/public/io/console.h | 13 +++++++++ 8 files changed, 63 insertions(+), 5 deletions(-)
Quoted 3 lines
For the series:
Reviewed-by Juergen Gross <[email protected]>
For the series:
Hi Oleksii,
I think this series needs your "release-ack" tag.
Thanks,
Signature · 1 line
Anthony PERARD
Quoted 21 lines · Anthony PERARD
Quoted 20 lines · Jürgen Groß
Quoted 19 lines · Jason Andryuk
Add a connection flag to the console interface page so a domain can tell if it is connected or not. This became a series in v2 to add flag setting to libxenguest.
Jason Andryuk (3):
xenconsole: Add connection flag libs/guest: Set console page to disconnected libs/guest: Set console as disconnected on resumetools/console/daemon/io.c | 4 +++ tools/include/xenguest.h | 4 +++ tools/libs/guest/xg_dom_arm.c | 2 +- tools/libs/guest/xg_dom_boot.c | 36 ++++++++++++++++++++++++ tools/libs/guest/xg_dom_x86.c | 6 ++-- tools/libs/guest/xg_sr_restore_x86_hvm.c | 2 +- tools/libs/guest/xg_sr_restore_x86_pv.c | 1 + xen/include/public/io/console.h | 13 +++++++++ 8 files changed, 63 insertions(+), 5 deletions(-)
Quoted 8 lines
Quoted 3 lines
For the series:
Reviewed-by Juergen Gross<[email protected]>For the series:
Acked-by Anthony PERARD<[email protected]>Hi Oleksii,
I think this series needs your "release-ack" tag.\
It is a little bit too late. But considering that this patch should increase boot performance (right?) and it is pretty straightforward, I think (IIUC regarding boot performance) we can consider these patch series to be in 4.21:
~ Oleksii