From nobody Sun May 12 07:20:10 2024 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; dmarc=pass(p=none dis=none) header.from=kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1651266660; cv=none; d=zohomail.com; s=zohoarc; b=Vukd46cN9MG9eTdcIWHkCdKXweOEJ/A12aWhphLs2njh4VAKZmGEbg8kLZFYF6Pe6vf/ZIhKakkBTSB0wHb9mgbmhS6jqSCJjWYpANjBnISu1LrawDggWZzixzimrwjalk5NKbmKatbWzUjrj/H+uPc4PxcEI0NYTmDJlkGTVN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651266660; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=aA9fXWS3dsm0gjYiM/lvvQlQqsuvYSwcF2BCv7O7fHc=; b=CPM1dFw09nzPQ34LuAuTLuhE64/NVviY9l3eFwbwbG7WqQCr4PNhcKhdxWBeQeMwT+blnF4qdSMZ0DM3Py8FoltOICv2/h1awjmf6AODt6Sl1EpFLnGO/xebnaMt6Izt4QAG3mYenR3DvzT4OWPiKSd0TWARorK/gAsaD6DKf2s= 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1651266660497293.08746610069045; Fri, 29 Apr 2022 14:11:00 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.317758.537250 (Exim 4.92) (envelope-from ) id 1nkXsn-0005Z7-RV; Fri, 29 Apr 2022 21:10:33 +0000 Received: by outflank-mailman (output) from mailman id 317758.537250; Fri, 29 Apr 2022 21:10:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nkXsn-0005Z0-N0; Fri, 29 Apr 2022 21:10:33 +0000 Received: by outflank-mailman (input) for mailman id 317758; Fri, 29 Apr 2022 21:10:33 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nkXsn-0005Yu-BJ for xen-devel@lists.xenproject.org; Fri, 29 Apr 2022 21:10:33 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [2604:1380:4641:c500::1]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id cd00835f-c800-11ec-8fc4-03012f2f19d4; Fri, 29 Apr 2022 23:10:31 +0200 (CEST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 48B056222F; Fri, 29 Apr 2022 21:10:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C0BDFC385A4; Fri, 29 Apr 2022 21:10:29 +0000 (UTC) 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 Sender: "Xen-devel" X-Inumbo-ID: cd00835f-c800-11ec-8fc4-03012f2f19d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651266630; bh=KmdTjeuSqmh9CE/tUKpNwFrF67mIaEHHOltqgoCVtxU=; h=From:To:Cc:Subject:Date:From; b=PzF6qHNaUB/VAMyIG0sbhyLAUhcomOyqMW5RBsN/PwMcQx8Onu6SZGUaqqtlrdSfL wXYHCcb5v6M9tfxr1jcujJLv/WFIZvEN/DVe+tWMb+ULLDqSynkSzMngh5KVSImNTc AA01tsxJXXdWhN5hxqNcIwlUo+DcQXNA84G38YdeJ6zAg4rK3aqv2XoiNwY7tlsOef DpYpi17UELRvIy7FP7qtK7DfzCeFmOVwr2vvQJHEnS5+rFRjj/M5qUSu9hB9UCXQ67 3vmjesrEkA4OfY42Q17o1JqVX6L5xqMPs1vpNrOqqUvUUETVYvPmZETLkoHXsihGuZ rcK06oCBG+tDA== From: Stefano Stabellini To: xen-devel@lists.xenproject.org Cc: sstabellini@kernel.org, Luca Miccio , Stefano Stabellini , jgross@suse.com, boris.ostrovsky@oracle.com Subject: [LINUX PATCH v3] xen: add support for initializing xenstore later as HVM domain Date: Fri, 29 Apr 2022 14:10:27 -0700 Message-Id: <20220429211027.2034134-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1651266661413100001 Content-Type: text/plain; charset="utf-8" From: Luca Miccio When running as dom0less guest (HVM domain on ARM) the xenstore event channel is available at domain creation but the shared xenstore interface page only becomes available later on. In that case, wait for a notification on the xenstore event channel, then complete the xenstore initialization later, when the shared page is actually available. The xenstore page has few extra field. Add them to the shared struct. One of the field is "connection", when the connection is ready, it is zero. If the connection is not-zero, wait for a notification. Signed-off-by: Luca Miccio Signed-off-by: Stefano Stabellini CC: jgross@suse.com CC: boris.ostrovsky@oracle.com --- Changes in v3: - check for the connection field, if it is not zero, wait for event Changes in v2: - remove XENFEAT_xenstore_late_init --- drivers/xen/xenbus/xenbus_probe.c | 86 +++++++++++++++++++++++------- include/xen/interface/io/xs_wire.h | 3 ++ 2 files changed, 70 insertions(+), 19 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index fe360c33ce71..dc046d25789e 100644 --- a/drivers/xen/xenbus/xenbus_probe.c +++ b/drivers/xen/xenbus/xenbus_probe.c @@ -65,6 +65,7 @@ #include "xenbus.h" =20 =20 +static int xs_init_irq; int xen_store_evtchn; EXPORT_SYMBOL_GPL(xen_store_evtchn); =20 @@ -750,6 +751,17 @@ static void xenbus_probe(void) { xenstored_ready =3D 1; =20 + if (!xen_store_interface) { + xen_store_interface =3D xen_remap(xen_store_gfn << XEN_PAGE_SHIFT, + XEN_PAGE_SIZE); + /* + * Now it is safe to free the IRQ used for xenstore late + * initialization. No need to unbind: it is about to be + * bound again. + */ + free_irq(xs_init_irq, &xb_waitq); + } + /* * In the HVM case, xenbus_init() deferred its call to * xs_init() in case callbacks were not operational yet. @@ -798,20 +810,22 @@ static int __init xenbus_probe_initcall(void) { /* * 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. + * need to wait for the platform PCI device to come up or + * xen_store_interface is not ready. */ if (xen_store_domain_type =3D=3D XS_PV || (xen_store_domain_type =3D=3D XS_HVM && - !xs_hvm_defer_init_for_callback())) + !xs_hvm_defer_init_for_callback() && + xen_store_interface !=3D NULL)) xenbus_probe(); =20 /* - * For XS_LOCAL, spawn a thread which will wait for xenstored - * or a xenstore-stubdom to be started, then probe. It will be - * triggered when communication starts happening, by waiting - * on xb_waitq. + * For XS_LOCAL or when xen_store_interface is not ready, spawn a + * thread which will wait for xenstored or a xenstore-stubdom to be + * started, then probe. It will be triggered when communication + * starts happening, by waiting on xb_waitq. */ - if (xen_store_domain_type =3D=3D XS_LOCAL) { + if (xen_store_domain_type =3D=3D XS_LOCAL || xen_store_interface =3D=3D N= ULL) { struct task_struct *probe_task; =20 probe_task =3D kthread_run(xenbus_probe_thread, NULL, @@ -907,10 +921,25 @@ static struct notifier_block xenbus_resume_nb =3D { .notifier_call =3D xenbus_resume_cb, }; =20 +static irqreturn_t xenbus_late_init(int irq, void *unused) +{ + int err =3D 0; + uint64_t v =3D 0; + + err =3D hvm_get_parameter(HVM_PARAM_STORE_PFN, &v); + if (err || !v || !~v) + return IRQ_HANDLED; + xen_store_gfn =3D (unsigned long)v; + + wake_up(&xb_waitq); + return IRQ_HANDLED; +} + static int __init xenbus_init(void) { int err; uint64_t v =3D 0; + bool wait =3D false; xen_store_domain_type =3D XS_UNKNOWN; =20 if (!xen_domain()) @@ -959,23 +988,42 @@ static int __init xenbus_init(void) * * Also recognize all bits set as an invalid value. */ - if (!v || !~v) { + if (!v) { err =3D -ENOENT; goto out_error; } - /* Avoid truncation on 32-bit. */ + if (v =3D=3D ~0ULL) { + wait =3D true; + } else { + /* Avoid truncation on 32-bit. */ #if BITS_PER_LONG =3D=3D 32 - if (v > ULONG_MAX) { - pr_err("%s: cannot handle HVM_PARAM_STORE_PFN=3D%llx > ULONG_MAX\n", - __func__, v); - err =3D -EINVAL; - goto out_error; - } + if (v > ULONG_MAX) { + pr_err("%s: cannot handle HVM_PARAM_STORE_PFN=3D%llx > ULONG_MAX\n", + __func__, v); + err =3D -EINVAL; + goto out_error; + } #endif - xen_store_gfn =3D (unsigned long)v; - xen_store_interface =3D - xen_remap(xen_store_gfn << XEN_PAGE_SHIFT, - XEN_PAGE_SIZE); + xen_store_gfn =3D (unsigned long)v; + xen_store_interface =3D + xen_remap(xen_store_gfn << XEN_PAGE_SHIFT, + XEN_PAGE_SIZE); + if (xen_store_interface->connection !=3D 0) + wait =3D true; + } + if (wait) { + err =3D bind_evtchn_to_irqhandler(xen_store_evtchn, + xenbus_late_init, + 0, "xenstore_late_init", + &xb_waitq); + if (err < 0) { + pr_err("xenstore_late_init couldn't bind irq err=3D%d\n", + err); + return err; + } + + xs_init_irq =3D err; + } break; default: pr_warn("Xenstore state unknown\n"); diff --git a/include/xen/interface/io/xs_wire.h b/include/xen/interface/io/= xs_wire.h index d40a44f09b16..cd7ae5ebb133 100644 --- a/include/xen/interface/io/xs_wire.h +++ b/include/xen/interface/io/xs_wire.h @@ -87,6 +87,9 @@ struct xenstore_domain_interface { char rsp[XENSTORE_RING_SIZE]; /* Replies and async watch events. */ XENSTORE_RING_IDX req_cons, req_prod; XENSTORE_RING_IDX rsp_cons, rsp_prod; + uint32_t server_features; /* Bitmap of features supported by the serve= r */ + uint32_t connection; + uint32_t error; }; =20 /* Violating this is very bad. See docs/misc/xenstore.txt. */ --=20 2.25.1