Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit a360758

Browse files
Henry Wangjgross1
authored andcommitted
drivers/xen: Improve the late XenStore init protocol
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: 5b33539 ("xen: add support for initializing xenstore later as HVM domain") Signed-off-by: Henry Wang <xin.wang2@amd.com> Signed-off-by: Michal Orzel <michal.orzel@amd.com> Reviewed-by: Stefano Stabellini <sstabellini@kernel.org> Link: https://lore.kernel.org/r/20240517011516.1451087-1-xin.wang2@amd.com Signed-off-by: Juergen Gross <jgross@suse.com>
1 parent 89af61f commit a360758

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

drivers/xen/xenbus/xenbus_probe.c

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,17 @@
6565
#include "xenbus.h"
6666

6767

68-
static int xs_init_irq;
68+
static int xs_init_irq = -1;
6969
int xen_store_evtchn;
7070
EXPORT_SYMBOL_GPL(xen_store_evtchn);
7171

7272
struct xenstore_domain_interface *xen_store_interface;
7373
EXPORT_SYMBOL_GPL(xen_store_interface);
7474

75+
#define XS_INTERFACE_READY \
76+
((xen_store_interface != NULL) && \
77+
(xen_store_interface->connection == XENSTORE_CONNECTED))
78+
7579
enum xenstore_init xen_store_domain_type;
7680
EXPORT_SYMBOL_GPL(xen_store_domain_type);
7781

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

754-
if (!xen_store_interface) {
758+
if (!xen_store_interface)
755759
xen_store_interface = memremap(xen_store_gfn << XEN_PAGE_SHIFT,
756760
XEN_PAGE_SIZE, MEMREMAP_WB);
757-
/*
758-
* Now it is safe to free the IRQ used for xenstore late
759-
* initialization. No need to unbind: it is about to be
760-
* bound again from xb_init_comms. Note that calling
761-
* unbind_from_irqhandler now would result in xen_evtchn_close()
762-
* being called and the event channel not being enabled again
763-
* afterwards, resulting in missed event notifications.
764-
*/
761+
/*
762+
* Now it is safe to free the IRQ used for xenstore late
763+
* initialization. No need to unbind: it is about to be
764+
* bound again from xb_init_comms. Note that calling
765+
* unbind_from_irqhandler now would result in xen_evtchn_close()
766+
* being called and the event channel not being enabled again
767+
* afterwards, resulting in missed event notifications.
768+
*/
769+
if (xs_init_irq >= 0)
765770
free_irq(xs_init_irq, &xb_waitq);
766-
}
767771

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

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

837841
probe_task = kthread_run(xenbus_probe_thread, NULL,
@@ -1014,6 +1018,12 @@ static int __init xenbus_init(void)
10141018
xen_store_interface =
10151019
memremap(xen_store_gfn << XEN_PAGE_SHIFT,
10161020
XEN_PAGE_SIZE, MEMREMAP_WB);
1021+
if (!xen_store_interface) {
1022+
pr_err("%s: cannot map HVM_PARAM_STORE_PFN=%llx\n",
1023+
__func__, v);
1024+
err = -EINVAL;
1025+
goto out_error;
1026+
}
10171027
if (xen_store_interface->connection != XENSTORE_CONNECTED)
10181028
wait = true;
10191029
}

0 commit comments

Comments
 (0)