From nobody Tue Feb 10 13:34:01 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1609947676; cv=none; d=zohomail.com; s=zohoarc; b=mWZbXYQ09dkNCKobFehdN5pYuJ3IhHvjp7tyU3Eooy965z0Uu7/VqhdBw+OwNviIVUu00a1akuLsEpZ6OFhgsTojo9w3wxBxixeg9v1R6Gqw8dFJDSYZzyg2KXljlDcoy9z55VaIOk5LyEFWI2cBMqHEY/Uc5IFirqtx2ZIURds= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1609947676; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5PjujQZ9wwpjTNtRotMyqGzLTZB87ASy5Gvxw2Qw3ZE=; b=K5XGtO2nCenCWTXw04puTlpYzFdMX/NJAm2C4RHHrsSaFnuak3+rkuyooEqMDdTjEpNaZJrjMcF7imRkxgo2kxDZksVR4GpJFx/l9BlTZ710pA57zGxuk19RPEaVFsgnkiHQGOwte5v8yhINQS91Ee9eJJu2WQ2Ntd3xghB6hgQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1609947676331175.13361451544563; Wed, 6 Jan 2021 07:41:16 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.62543.110839 (Exim 4.92) (envelope-from ) id 1kxAvi-000547-VS; Wed, 06 Jan 2021 15:40:58 +0000 Received: by outflank-mailman (output) from mailman id 62543.110839; Wed, 06 Jan 2021 15:40:58 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxAvi-00053v-PT; Wed, 06 Jan 2021 15:40:58 +0000 Received: by outflank-mailman (input) for mailman id 62543; Wed, 06 Jan 2021 15:40:57 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kxAvh-00053E-BL for xen-devel@lists.xenproject.org; Wed, 06 Jan 2021 15:40:57 +0000 Received: from casper.infradead.org (unknown [2001:8b0:10b:1236::1]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0f11ec4b-6743-4a31-b5cf-9776d94f0702; Wed, 06 Jan 2021 15:40:52 +0000 (UTC) Received: from i7.infradead.org ([2001:8b0:10b:1:21e:67ff:fecb:7a92]) by casper.infradead.org with esmtpsa (Exim 4.94 #2 (Red Hat Linux)) id 1kxAun-002TH2-UV; Wed, 06 Jan 2021 15:40:12 +0000 Received: from dwoodhou by i7.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1kxAul-002S1w-TS; Wed, 06 Jan 2021 15:39:59 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list X-Inumbo-ID: 0f11ec4b-6743-4a31-b5cf-9776d94f0702 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Sender:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description; bh=5PjujQZ9wwpjTNtRotMyqGzLTZB87ASy5Gvxw2Qw3ZE=; b=edoa/S+MleZvGzRxIIgtWZHD9T c5/i2PrZCUvN1FfeavcfaoDvmHBqoWFHUFZ8Xy6XSiYkR+yBmRq3dY0BxQnrfpj3XHgEmqmZm5F+I fmsRDH1BfLuaN/mlBbjpbd+4xv2Sd/Ari+9RVDbabH4tuPVkj7YZLSI9H3WKqCnmVG3OSZYH3UpG2 lkwTrx/Y9OxpsWejao0To4rvrxbrTLHNfOqRfa9OAcRR+C5S2shQwzMPlGa1kT6ADFmykD/y73KWv tj4txpzpvNXp56B3YA8QBXJu6Sjp6z+3SHKKJi3xBQg3TLo3NKozh/iCRetHby29YslNSZi24cfWg 39fTN5BA==; From: David Woodhouse To: x86@kernel.org Cc: Stefano Stabellini , Boris Ostrovsky , Juergen Gross , Paul Durrant , jgrall@amazon.com, karahmed@amazon.de, xen-devel Subject: [PATCH v3 1/5] xen: Fix event channel callback via INTX/GSI Date: Wed, 6 Jan 2021 15:39:54 +0000 Message-Id: <20210106153958.584169-2-dwmw2@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210106153958.584169-1-dwmw2@infradead.org> References: <20210106153958.584169-1-dwmw2@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: David Woodhouse X-SRS-Rewrite: SMTP reverse-path rewritten from by casper.infradead.org. See http://www.infradead.org/rpr.html X-ZohoMail-DKIM: pass (identity @infradead.org) Content-Type: text/plain; charset="utf-8" From: David Woodhouse For a while, event channel notification via the PCI platform device has been broken, because we attempt to communicate with xenstore before we even have notifications working, with the xs_reset_watches() call in xs_init(). We tend to get away with this on Xen versions below 4.0 because we avoid calling xs_reset_watches() anyway, because xenstore might not cope with reading a non-existent key. And newer Xen *does* have the vector callback support, so we rarely fall back to INTX/GSI delivery. To fix it, clean up a bit of the mess of xs_init() and xenbus_probe() startup. Call xs_init() directly from xenbus_init() only in the !XS_HVM case, deferring it to be called from xenbus_probe() in the XS_HVM case instead. Then fix up the invocation of xenbus_probe() to happen either from its device_initcall if the callback is available early enough, or when the callback is finally set up. This means that the hack of calling xenbus_probe() from a workqueue after the first interrupt, or directly from the PCI platform device setup, is no longer needed. Signed-off-by: David Woodhouse Reviewed-by: Boris Ostrovsky --- arch/arm/xen/enlighten.c | 2 +- drivers/xen/events/events_base.c | 10 ----- drivers/xen/platform-pci.c | 1 - drivers/xen/xenbus/xenbus.h | 1 + drivers/xen/xenbus/xenbus_comms.c | 8 ---- drivers/xen/xenbus/xenbus_probe.c | 68 ++++++++++++++++++++++++------- include/xen/xenbus.h | 2 +- 7 files changed, 57 insertions(+), 35 deletions(-) diff --git a/arch/arm/xen/enlighten.c b/arch/arm/xen/enlighten.c index 60e901cd0de6..5a957a9a0984 100644 --- a/arch/arm/xen/enlighten.c +++ b/arch/arm/xen/enlighten.c @@ -371,7 +371,7 @@ static int __init xen_guest_init(void) } gnttab_init(); if (!xen_initial_domain()) - xenbus_probe(NULL); + xenbus_probe(); =20 /* * Making sure board specific code will not set up ops for diff --git a/drivers/xen/events/events_base.c b/drivers/xen/events/events_b= ase.c index a8030332a191..e850f79351cb 100644 --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -2060,16 +2060,6 @@ static struct irq_chip xen_percpu_chip __read_mostly= =3D { .irq_ack =3D ack_dynirq, }; =20 -int xen_set_callback_via(uint64_t via) -{ - struct xen_hvm_param a; - a.domid =3D DOMID_SELF; - a.index =3D HVM_PARAM_CALLBACK_IRQ; - a.value =3D via; - return HYPERVISOR_hvm_op(HVMOP_set_param, &a); -} -EXPORT_SYMBOL_GPL(xen_set_callback_via); - #ifdef CONFIG_XEN_PVHVM /* Vector callbacks are better than PCI interrupts to receive event * channel notifications because we can receive vector callbacks on any diff --git a/drivers/xen/platform-pci.c b/drivers/xen/platform-pci.c index dd911e1ff782..9db557b76511 100644 --- a/drivers/xen/platform-pci.c +++ b/drivers/xen/platform-pci.c @@ -149,7 +149,6 @@ static int platform_pci_probe(struct pci_dev *pdev, ret =3D gnttab_init(); if (ret) goto grant_out; - xenbus_probe(NULL); return 0; grant_out: gnttab_free_auto_xlat_frames(); diff --git a/drivers/xen/xenbus/xenbus.h b/drivers/xen/xenbus/xenbus.h index 2a93b7c9c159..dc1537335414 100644 --- a/drivers/xen/xenbus/xenbus.h +++ b/drivers/xen/xenbus/xenbus.h @@ -115,6 +115,7 @@ int xenbus_probe_node(struct xen_bus_type *bus, const char *type, const char *nodename); int xenbus_probe_devices(struct xen_bus_type *bus); +void xenbus_probe(void); =20 void xenbus_dev_changed(const char *node, struct xen_bus_type *bus); =20 diff --git a/drivers/xen/xenbus/xenbus_comms.c b/drivers/xen/xenbus/xenbus_= comms.c index eb5151fc8efa..e5fda0256feb 100644 --- a/drivers/xen/xenbus/xenbus_comms.c +++ b/drivers/xen/xenbus/xenbus_comms.c @@ -57,16 +57,8 @@ DEFINE_MUTEX(xs_response_mutex); static int xenbus_irq; static struct task_struct *xenbus_task; =20 -static DECLARE_WORK(probe_work, xenbus_probe); - - static irqreturn_t wake_waiting(int irq, void *unused) { - if (unlikely(xenstored_ready =3D=3D 0)) { - xenstored_ready =3D 1; - schedule_work(&probe_work); - } - wake_up(&xb_waitq); return IRQ_HANDLED; } diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index 44634d970a5c..b1b5b6fe9b52 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -683,29 +683,63 @@ void unregister_xenstore_notifier(struct notifier_blo= ck *nb) } EXPORT_SYMBOL_GPL(unregister_xenstore_notifier); =20 -void xenbus_probe(struct work_struct *unused) +void xenbus_probe(void) { xenstored_ready =3D 1; =20 + /* + * In the HVM case, xenbus_init() deferred its call to + * xs_init() in case callbacks were not operational yet. + * So do it now. + */ + if (xen_store_domain_type =3D=3D XS_HVM) + xs_init(); + /* Notify others that xenstore is up */ blocking_notifier_call_chain(&xenstore_chain, 0, NULL); } -EXPORT_SYMBOL_GPL(xenbus_probe); =20 static int __init xenbus_probe_initcall(void) { - if (!xen_domain()) - return -ENODEV; - - if (xen_initial_domain() || xen_hvm_domain()) - return 0; + /* + * Probe XenBus here in the XS_PV case, and also XS_HVM unless we + * need to wait for the platform PCI device to come up, which is + * the (XEN_PVPVM && !xen_have_vector_callback) case. + */ + if (xen_store_domain_type =3D=3D XS_PV || + (xen_store_domain_type =3D=3D XS_HVM && + (!IS_ENABLED(CONFIG_XEN_PVHVM) || xen_have_vector_callback))) + xenbus_probe(); =20 - xenbus_probe(NULL); return 0; } - device_initcall(xenbus_probe_initcall); =20 +int xen_set_callback_via(uint64_t via) +{ + struct xen_hvm_param a; + int ret; + + a.domid =3D DOMID_SELF; + a.index =3D HVM_PARAM_CALLBACK_IRQ; + a.value =3D via; + + ret =3D HYPERVISOR_hvm_op(HVMOP_set_param, &a); + if (ret) + return ret; + + /* + * If xenbus_probe_initcall() deferred the xenbus_probe() + * due to the callback not functioning yet, we can do it now. + */ + if (!xenstored_ready && xen_store_domain_type =3D=3D XS_HVM && + IS_ENABLED(CONFIG_XEN_PVHVM) && !xen_have_vector_callback) + xenbus_probe(); + + return ret; +} +EXPORT_SYMBOL_GPL(xen_set_callback_via); + /* Set up event channel for xenstored which is run as a local process * (this is normally used only in dom0) */ @@ -818,11 +852,17 @@ static int __init xenbus_init(void) break; } =20 - /* Initialize the interface to xenstore. */ - err =3D xs_init(); - if (err) { - pr_warn("Error initializing xenstore comms: %i\n", err); - goto out_error; + /* + * HVM domains may not have a functional callback yet. In that + * case let xs_init() be called from xenbus_probe(), which will + * get invoked at an appropriate time. + */ + if (xen_store_domain_type !=3D XS_HVM) { + err =3D xs_init(); + if (err) { + pr_warn("Error initializing xenstore comms: %i\n", err); + goto out_error; + } } =20 if ((xen_store_domain_type !=3D XS_LOCAL) && diff --git a/include/xen/xenbus.h b/include/xen/xenbus.h index 00c7235ae93e..2c43b0ef1e4d 100644 --- a/include/xen/xenbus.h +++ b/include/xen/xenbus.h @@ -192,7 +192,7 @@ void xs_suspend_cancel(void); =20 struct work_struct; =20 -void xenbus_probe(struct work_struct *); +void xenbus_probe(void); =20 #define XENBUS_IS_ERR_READ(str) ({ \ if (!IS_ERR(str) && strlen(str) =3D=3D 0) { \ --=20 2.29.2