Skip to contentSkip to conversation

x86/platform: make XENPF_get_dom0_console actually usable

PATCH In review Jan Beulich 2 participants 3 messages Feb 13, 2023 – Mar 13, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/platform: make XENPF_get_dom0_console actually usable

struct dom0_vga_console_info has been extended in the past, and it may be extended again. The use in PV Dom0's start info already covers for that by supplying the size of the provided data. For the recently introduced platform-op size needs providing similarly. Go the easiest available route and simply supply size via the hypercall return value.

While there also add a build-time check that possibly future growth of the struct won't affect xen_platform_op_t's size.

Fixes 4dd160583c79 ("x86/platform: introduce hypercall to get initial video console settings")

---
Noticed while trying to actually use the new hypercall in Linux.

xen/arch/x86/platform_hypercall.c +2 -0
@@ -841,6 +841,8 @@ ret_t do_platform_op(
 
 #ifdef CONFIG_VIDEO
     case XENPF_get_dom0_console:
+        BUILD_BUG_ON(sizeof(op->u.dom0_console) > sizeof(op->u.pad));
+        ret = sizeof(op->u.dom0_console);
         if ( !fill_console_start_info(&op->u.dom0_console) )
         {
             ret = -ENODEV;
#1 lore raw
Quoted 18 lines · Jan Beulich

struct dom0_vga_console_info has been extended in the past, and it may be extended again. The use in PV Dom0's start info already covers for that by supplying the size of the provided data. For the recently introduced platform-op size needs providing similarly. Go the easiest available route and simply supply size via the hypercall return value.

While there also add a build-time check that possibly future growth of the struct won't affect xen_platform_op_t's size.

Fixes 4dd160583c79 ("x86/platform: introduce hypercall to get initial video console settings")

---
Noticed while trying to actually use the new hypercall in Linux.

xen/arch/x86/platform_hypercall.c ret_t do_platform_op( · line 848

Quoted 8 lines
xen/arch/x86/platform_hypercall.c +2 -0
@@ -841,6 +841,8 @@ ret_t do_platform_op(
 
 #ifdef CONFIG_VIDEO
     case XENPF_get_dom0_console:
+        BUILD_BUG_ON(sizeof(op->u.dom0_console) > sizeof(op->u.pad));
+        ret = sizeof(op->u.dom0_console);
         if ( !fill_console_start_info(&op->u.dom0_console) )
         {
             ret = -ENODEV;

Thinking about it, I've added the hunk below.

Jan

xen/include/public/platform.h +5 -1
@@ -605,7 +605,11 @@ struct xenpf_symdata {
 typedef struct xenpf_symdata xenpf_symdata_t;
 DEFINE_XEN_GUEST_HANDLE(xenpf_symdata_t);
 
-/* Fetch the video console information and mode setup by Xen. */
+/*
+ * Fetch the video console information and mode setup by Xen.  A non-
+ * negative return value indicates the size of the (part of the) structure
+ * which was filled.
+ */
 #define XENPF_get_dom0_console 64
 typedef struct dom0_vga_console_info xenpf_dom0_console_t;
 DEFINE_XEN_GUEST_HANDLE(xenpf_dom0_console_t);
Acked-by on v1 1/1
#2 lore raw
In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

struct dom0_vga_console_info has been extended in the past, and it may be extended again. The use in PV Dom0's start info already covers for that by supplying the size of the provided data. For the recently introduced platform-op size needs providing similarly. Go the easiest available route and simply supply size via the hypercall return value.

While there also add a build-time check that possibly future growth of the struct won't affect xen_platform_op_t's size.

Fixes 4dd160583c79 ("x86/platform: introduce hypercall to get initial video console settings")

With the added comment.

Thanks, Roger.