From nobody Fri Nov 29 01:58:57 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=1651710215; cv=none; d=zohomail.com; s=zohoarc; b=TbnbT4c1Q0If8konLOciCGr8KhtLxYOdZLzTwv/RliZAmqXPi9ZGZFdUIhla5gE7tYL6AvrCcuHzbwQHfA2/pJrzCQcTkyC8EnR7qneHOkMNzJ/7QaVQ6uSQTFQhnn2argvlzrxVqw/SuMOe8l9i6bog23n2AkG7GbiJp0ghV90= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651710215; 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=w0EbmLqwq/pJII39mlbnm6fYP5pAyUcLdV/iwhp7tzY=; b=O59mn2nGhoQALlGwWGZlHZ9dmiAMXH5zzmACxVsCl2du6aj1jN2CIvp9+YWrQST+zjUvCmf29qrK9PevZwxYXgZTYOZJyLbPJ0MWFnYStEedqDUvKah9Jz8PIksnzbRowlzWJeCIuCaNopzGn+6teFQwk3loeBiRhG7ZvJDbvZ0= 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 165171021508295.77174365184919; Wed, 4 May 2022 17:23:35 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321228.542180 (Exim 4.92) (envelope-from ) id 1nmPGw-0004qS-2y; Thu, 05 May 2022 00:23:10 +0000 Received: by outflank-mailman (output) from mailman id 321228.542180; Thu, 05 May 2022 00:23:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPGv-0004qL-Vc; Thu, 05 May 2022 00:23:09 +0000 Received: by outflank-mailman (input) for mailman id 321228; Thu, 05 May 2022 00:23:08 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPGu-0004pS-NF for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:23:08 +0000 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 890976fb-cc09-11ec-a406-831a346695d4; Thu, 05 May 2022 02:23:07 +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 84DB761D47; Thu, 5 May 2022 00:23:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9000C385A5; Thu, 5 May 2022 00:23:05 +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: 890976fb-cc09-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651710185; bh=HFLLzAtqSAhevBTNCZk3OMTL3poJMeEW0dWOHMZLBNA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BQp06t9UrtZbQwSSdyMAde3poqr3W4rwIegP9HDgHxNqJwYhUJclsMyS7/BSekUYN eMLtojNJl4Gl+cxR2pHBW++i9NV6nEO4TIBpp3NBTcq+h8T4qq3VixHHkRIUl0JY/B xE8gD9+bHb5Yx6gOQA0xmQS3Y10kx5vu74flOWV4OCyO5VYcdfXSYCYJMtBeK5Stko Cb8keVZzu9OWU955B6ZfAPvyYdPa4zI4tyzVCJebjcZ1jvtyMiaj3JfZ6SPB2YoCt7 al93Oe2uPdGzBU1l3hSUy8gvyJVHXv/xmAwFO5cQgrxFKyrZ5xFlZzxKdm94jzRFFv bscsu/OK1DzQA== From: Stefano Stabellini To: boris.ostrovsky@oracle.com, jgross@suse.com Cc: sstabellini@kernel.org, xen-devel@lists.xenproject.org, Stefano Stabellini Subject: [PATCH v4 1/2] xen: sync xs_wire.h header with upstream xen Date: Wed, 4 May 2022 17:23:03 -0700 Message-Id: <20220505002304.401417-1-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1651710216775100003 Content-Type: text/plain; charset="utf-8" From: Stefano Stabellini Sync the xs_wire.h header file in Linux with the one in Xen. Signed-off-by: Stefano Stabellini --- include/xen/interface/io/xs_wire.h | 34 +++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/include/xen/interface/io/xs_wire.h b/include/xen/interface/io/= xs_wire.h index d40a44f09b16..04dca77abc45 100644 --- a/include/xen/interface/io/xs_wire.h +++ b/include/xen/interface/io/xs_wire.h @@ -10,7 +10,8 @@ =20 enum xsd_sockmsg_type { - XS_DEBUG, + XS_CONTROL, +#define XS_DEBUG XS_CONTROL XS_DIRECTORY, XS_READ, XS_GET_PERMS, @@ -30,8 +31,13 @@ enum xsd_sockmsg_type XS_IS_DOMAIN_INTRODUCED, XS_RESUME, XS_SET_TARGET, - XS_RESTRICT, - XS_RESET_WATCHES, + /* XS_RESTRICT has been removed */ + XS_RESET_WATCHES =3D XS_SET_TARGET + 2, + XS_DIRECTORY_PART, + + XS_TYPE_COUNT, /* Number of valid types. */ + + XS_INVALID =3D 0xffff /* Guaranteed to remain an invalid type */ }; =20 #define XS_WRITE_NONE "NONE" @@ -87,9 +93,31 @@ 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. */ #define XENSTORE_PAYLOAD_MAX 4096 =20 +/* Violating these just gets you an error back */ +#define XENSTORE_ABS_PATH_MAX 3072 +#define XENSTORE_REL_PATH_MAX 2048 + +/* The ability to reconnect a ring */ +#define XENSTORE_SERVER_FEATURE_RECONNECTION 1 +/* The presence of the "error" field in the ring page */ +#define XENSTORE_SERVER_FEATURE_ERROR 2 + +/* Valid values for the connection field */ +#define XENSTORE_CONNECTED 0 /* the steady-state */ +#define XENSTORE_RECONNECT 1 /* guest has initiated a reconnect */ + +/* Valid values for the error field */ +#define XENSTORE_ERROR_NONE 0 /* No error */ +#define XENSTORE_ERROR_COMM 1 /* Communication problem */ +#define XENSTORE_ERROR_RINGIDX 2 /* Invalid ring index */ +#define XENSTORE_ERROR_PROTO 3 /* Protocol violation (payload too long) = */ + #endif /* _XS_WIRE_H */ --=20 2.25.1 From nobody Fri Nov 29 01:58:57 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=1651710213; cv=none; d=zohomail.com; s=zohoarc; b=NXbfyj3RH5r2WISWSYXf43CNvC3qWUCD+T0mSHWI91PuYXqOJyHCRSgiNxZbIHNW3HrSFhbcD7aUPl7oZpyD2tAuYKXGHP6mg0/zcGQvEbRwYazkGoLZeG5ypedIfmTR9D/gswgA/JDeLmfGioX2U0QNTT4vJUMc9Ro/auFbsHQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651710213; 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=+4ijAaPIkZiWafT4N36vydBXbi/bpCyHB/Jjk4Q3npM=; b=bZJWPjagnGKwqN3UcuDEs8MUMoVO0/+XRwcBfvJVc9ezr+PPlpKEgD6PswhjY28SQEWW1aEHu6KpVNdMOpfraLbDvgLMlShcdfqxVUiAcOdnbSnJwQ8WXePbjuEhchmlKahNxLnoQ4Kuf6pb+ONByJgTDrv4KmRC5nrnVYW7FHY= 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 1651710213228160.48584740474803; Wed, 4 May 2022 17:23:33 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.321229.542185 (Exim 4.92) (envelope-from ) id 1nmPGw-0004u0-Ig; Thu, 05 May 2022 00:23:10 +0000 Received: by outflank-mailman (output) from mailman id 321229.542185; Thu, 05 May 2022 00:23:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPGw-0004t7-AQ; Thu, 05 May 2022 00:23:10 +0000 Received: by outflank-mailman (input) for mailman id 321229; Thu, 05 May 2022 00:23:09 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1nmPGv-0004pS-Fc for xen-devel@lists.xenproject.org; Thu, 05 May 2022 00:23:09 +0000 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 8a0f85db-cc09-11ec-a406-831a346695d4; Thu, 05 May 2022 02:23:08 +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 ams.source.kernel.org (Postfix) with ESMTPS id C3698B81AF2; Thu, 5 May 2022 00:23:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1DA06C385AA; Thu, 5 May 2022 00:23:06 +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: 8a0f85db-cc09-11ec-a406-831a346695d4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651710186; bh=jzqqLYPIU8TZVMVWEtLKqhjo+o2vN0T5c9gjvg8DczU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJa8DW7x8TN40d7joD6W/6C38az0F/jRNXIG9CyyceJoYItNDMBkl/DLsFfNuMcHx W/PdfvS8c3bz38cQ1/kmOwFfWAwj+n0+udfAz0cM4edtjbKTzokjxAylNe6I9l7Ldz qdcQYqUu2tpZqNsWW50xItFPHBO0OFSPssK6J+YDzsLfzXDo5d/mJ+ZlOSE1YPvH0s MLG354Hq3fNC5C82yNKsrSfI9QjMUi/dsjOpC6CeJNvTnvdKUmtK3nMV/fRbHGnFR4 UvqmWgplAO57Xl3tkdr+6LwlTXRieCQWwauYMHO60qczyOYwhVZdTTisjpJlmQqUMG yyag0n/GHQtaQ== From: Stefano Stabellini To: boris.ostrovsky@oracle.com, jgross@suse.com Cc: sstabellini@kernel.org, xen-devel@lists.xenproject.org, Luca Miccio , Stefano Stabellini Subject: [PATCH v4 2/2] xen: add support for initializing xenstore later as HVM domain Date: Wed, 4 May 2022 17:23:04 -0700 Message-Id: <20220505002304.401417-2-sstabellini@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @kernel.org) X-ZM-MESSAGEID: 1651710214890100001 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 Reviewed-by: Boris Ostrovsky --- Changes in v4: - improve in-code comments - move header sync to separate patch - use XENSTORE_CONNECTED 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 | 91 ++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 20 deletions(-) diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_= probe.c index fe360c33ce71..0a785d5e3e40 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,20 @@ 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 from xb_init_comms. Note that calling + * unbind_from_irqhandler now would result in xen_evtchn_close() + * being called and the event channel not being enabled again + * afterwards, resulting in missed event notifications. + */ + 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 +813,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 +924,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()) @@ -957,25 +989,44 @@ static int __init xenbus_init(void) * been properly initialized. Instead of attempting to map a * wrong guest physical address return error. * - * Also recognize all bits set as an invalid value. + * Also recognize all bits set as an invalid/uninitialized 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 XENSTORE_CONNECTED) + 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"); --=20 2.25.1