Skip to contentSkip to conversation

xenbus: Allow PVH dom0 a non-local xenstore

PATCH Superseded Jason Andryuk 2 participants 4 messages May 3, 2025 – May 6, 2025 Xen hypervisor interface

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xenbus: Allow PVH dom0 a non-local xenstore

Make xenbus_init() allow a non-local xenstore for a PVH dom0 - it is currently forced to XS_LOCAL. With Hyperlaunch booting dom0 and a xenstore stubdom, dom0 can be handled as a regular XS_HVM following the late init path.

Drop the use of xen_initial_domain() and just check for the event channel instead. This matches the PV case where there is no check for initial domain.

Check the full 64bit HVM_PARAM_STORE_EVTCHN value to catch the off chance that high bits are set for the 32bit event channel.

---
 drivers/xen/xenbus/xenbus_probe.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +8 -6
index 6d32ffb01136..7604f70ee108 100644
@@ -966,9 +966,15 @@ static int __init xenbus_init(void)
 	if (xen_pv_domain())
 		xen_store_domain_type = XS_PV;
 	if (xen_hvm_domain())
+	{
 		xen_store_domain_type = XS_HVM;
-	if (xen_hvm_domain() && xen_initial_domain())
-		xen_store_domain_type = XS_LOCAL;
+		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
+		if (err)
+			goto out_error;
+		xen_store_evtchn = (int)v;
+		if (!v)
+			xen_store_domain_type = XS_LOCAL;
+	}
 	if (xen_pv_domain() && !xen_start_info->store_evtchn)
 		xen_store_domain_type = XS_LOCAL;
 	if (xen_pv_domain() && xen_start_info->store_evtchn)
@@ -987,10 +993,6 @@ static int __init xenbus_init(void)
 		xen_store_interface = gfn_to_virt(xen_store_gfn);
 		break;
 	case XS_HVM:
-		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
-		if (err)
-			goto out_error;
-		xen_store_evtchn = (int)v;
 		err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
 		if (err)
 			goto out_error;
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Jason Andryuk

Make xenbus_init() allow a non-local xenstore for a PVH dom0 - it is currently forced to XS_LOCAL. With Hyperlaunch booting dom0 and a xenstore stubdom, dom0 can be handled as a regular XS_HVM following the late init path.

Quoted 8 lines

Drop the use of xen_initial_domain() and just check for the event channel instead. This matches the PV case where there is no check for initial domain.

Check the full 64bit HVM_PARAM_STORE_EVTCHN value to catch the off chance that high bits are set for the 32bit event channel.

Quoted 40 lines
---
 drivers/xen/xenbus/xenbus_probe.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/xen/xenbus/xenbus_probe.c +8 -6
index 6d32ffb01136..7604f70ee108 100644
@@ -966,9 +966,15 @@ static int __init xenbus_init(void)
 	if (xen_pv_domain())
 		xen_store_domain_type = XS_PV;
 	if (xen_hvm_domain())
+	{
 		xen_store_domain_type = XS_HVM;
-	if (xen_hvm_domain() && xen_initial_domain())
-		xen_store_domain_type = XS_LOCAL;
+		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
+		if (err)
+			goto out_error;
+		xen_store_evtchn = (int)v;
+		if (!v)
+			xen_store_domain_type = XS_LOCAL;
+	}
 	if (xen_pv_domain() && !xen_start_info->store_evtchn)
 		xen_store_domain_type = XS_LOCAL;
 	if (xen_pv_domain() && xen_start_info->store_evtchn)
@@ -987,10 +993,6 @@ static int __init xenbus_init(void)
 		xen_store_interface = gfn_to_virt(xen_store_gfn);
 		break;
 	case XS_HVM:
-		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
-		if (err)
-			goto out_error;
-		xen_store_evtchn = (int)v;
 		err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
 		if (err)
 			goto out_error;
Signature · 1 line
2.34.1
#2 lore raw
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · Jason Andryuk

Make xenbus_init() allow a non-local xenstore for a PVH dom0 - it is currently forced to XS_LOCAL. With Hyperlaunch booting dom0 and a xenstore stubdom, dom0 can be handled as a regular XS_HVM following the late init path.

Drop the use of xen_initial_domain() and just check for the event channel instead. This matches the PV case where there is no check for initial domain.

Quoted 6 lines
Quoted 4 lines

Check the full 64bit HVM_PARAM_STORE_EVTCHN value to catch the off chance that high bits are set for the 32bit event channel.

Thanks, Stefano. But I'm wondering if this might break ARM enhanced no-xenstore.

Quoted 5 lines
Quoted 5 lines
---
  drivers/xen/xenbus/xenbus_probe.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
Quoted 10 lines

drivers/xen/xenbus/xenbus_probe.c static int __init xenbus_init(void) · line 970

Quoted 10 lines
drivers/xen/xenbus/xenbus_probe.c +1 -0
index 6d32ffb01136..7604f70ee108 100644
@@ -966,9 +966,15 @@ static int __init xenbus_init(void)
  	if (xen_pv_domain())
  		xen_store_domain_type = XS_PV;
  	if (xen_hvm_domain())
+	{
  		xen_store_domain_type = XS_HVM;

ARM would have everything set to XS_HVM...

Quoted 2 lines

drivers/xen/xenbus/xenbus_probe.c static int __init xenbus_init(void) · line 971

Quoted 2 lines
drivers/xen/xenbus/xenbus_probe.c +0 -2
-	if (xen_hvm_domain() && xen_initial_domain())
-		xen_store_domain_type = XS_LOCAL;

...and only dom0 set to XS_LOCAL.

Quoted 13 lines
Quoted 13 lines
drivers/xen/xenbus/xenbus_probe.c +7 -0
+		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
+		if (err)
+			goto out_error;
+		xen_store_evtchn = (int)v;
+		if (!v)
+			xen_store_domain_type = XS_LOCAL;
+	}
  	if (xen_pv_domain() && !xen_start_info->store_evtchn)
  		xen_store_domain_type = XS_LOCAL;
  	if (xen_pv_domain() && xen_start_info->store_evtchn)
@@ -987,10 +993,6 @@ static int __init xenbus_init(void)
  		xen_store_interface = gfn_to_virt(xen_store_gfn);
  		break;
Quoted 8 lines

drivers/xen/xenbus/xenbus_probe.c static int __init xenbus_init(void) · line 998

Quoted 8 lines
drivers/xen/xenbus/xenbus_probe.c +0 -4
  	case XS_HVM:
-		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
-		if (err)
-			goto out_error;
-		xen_store_evtchn = (int)v;
  		err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
  		if (err)
  			goto out_error;

/*
* Uninitialized hvm_params are zero and return no error.
* Although it is theoretically possible to have
* HVM_PARAM_STORE_PFN set to zero on purpose, in
reality it is
* not zero when valid. If zero, it means that Xenstore
hasn't
* been properly initialized. Instead of attempting to
map a
* wrong guest physical address return error. *
* Also recognize all bits set as an
invalid/uninitialized value.

                 */
                if (!v) {
                        err = -ENOENT;
                        goto out_error;
                }

IIUC, this !v check is for enhanced no-xenstore to end up in XS_UNKNOWN.
I'll have to re-work to handle that case.

Regards,
Jason

Quoted 3 lines
Quoted 3 lines
Signature · 1 line
2.34.1
#3 lore raw
Quoted 77 lines · Jason Andryuk
Quoted 10 lines · Stefano Stabellini
Quoted 9 lines · Jason Andryuk

Make xenbus_init() allow a non-local xenstore for a PVH dom0 - it is currently forced to XS_LOCAL. With Hyperlaunch booting dom0 and a xenstore stubdom, dom0 can be handled as a regular XS_HVM following the late init path.

Drop the use of xen_initial_domain() and just check for the event channel instead. This matches the PV case where there is no check for initial domain.

Quoted 6 lines
Quoted 4 lines

Check the full 64bit HVM_PARAM_STORE_EVTCHN value to catch the off chance that high bits are set for the 32bit event channel.

Thanks, Stefano. But I'm wondering if this might break ARM enhanced no-xenstore.

Quoted 5 lines
Quoted 5 lines
---
  drivers/xen/xenbus/xenbus_probe.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)
Quoted 11 lines

drivers/xen/xenbus/xenbus_probe.c static int __init xenbus_init(void) · line 970

Quoted 11 lines
drivers/xen/xenbus/xenbus_probe.c +1 -0
index 6d32ffb01136..7604f70ee108 100644
@@ -966,9 +966,15 @@ static int __init xenbus_init(void)
  	if (xen_pv_domain())
  		xen_store_domain_type = XS_PV;
  	if (xen_hvm_domain())
+	{
  		xen_store_domain_type = XS_HVM;

ARM would have everything set to XS_HVM...

Quoted 2 lines

drivers/xen/xenbus/xenbus_probe.c static int __init xenbus_init(void) · line 971

Quoted 2 lines
drivers/xen/xenbus/xenbus_probe.c +0 -2
-	if (xen_hvm_domain() && xen_initial_domain())
-		xen_store_domain_type = XS_LOCAL;

...and only dom0 set to XS_LOCAL.

Quoted 13 lines
Quoted 13 lines
drivers/xen/xenbus/xenbus_probe.c +7 -0
+		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
+		if (err)
+			goto out_error;
+		xen_store_evtchn = (int)v;
+		if (!v)
+			xen_store_domain_type = XS_LOCAL;
+	}
  	if (xen_pv_domain() && !xen_start_info->store_evtchn)
  		xen_store_domain_type = XS_LOCAL;
  	if (xen_pv_domain() && xen_start_info->store_evtchn)
@@ -987,10 +993,6 @@ static int __init xenbus_init(void)
  		xen_store_interface = gfn_to_virt(xen_store_gfn);
  		break;
Quoted 8 lines

drivers/xen/xenbus/xenbus_probe.c static int __init xenbus_init(void) · line 998

Quoted 8 lines
drivers/xen/xenbus/xenbus_probe.c +0 -4
  	case XS_HVM:
-		err = hvm_get_parameter(HVM_PARAM_STORE_EVTCHN, &v);
-		if (err)
-			goto out_error;
-		xen_store_evtchn = (int)v;
  		err = hvm_get_parameter(HVM_PARAM_STORE_PFN, &v);
  		if (err)
  			goto out_error;

/*
* Uninitialized hvm_params are zero and return no error.
* Although it is theoretically possible to have
* HVM_PARAM_STORE_PFN set to zero on purpose, in reality it
is
* not zero when valid. If zero, it means that Xenstore hasn't
* been properly initialized. Instead of attempting to map a
* wrong guest physical address return error.
*
* Also recognize all bits set as an invalid/uninitialized
value.

Quoted 8 lines
                 */
                if (!v) {
                        err = -ENOENT;
                        goto out_error;
                }

IIUC, this !v check is for enhanced no-xenstore to end up in XS_UNKNOWN. I'll have to re-work to handle that case.

I was wondering about that when reviewing this patch, because the removal of this check was the main change introduced I wasn't sure about. Looking around I (wrongly) convinced myself that removing the check was OK. Thank you for spotting this on your own.