Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp637050lqo; Thu, 16 May 2024 17:53:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVyCC+NAprS3xrcktR7QiCOQWJgf3WyJ3kHxbt6HBrkMgTie+eB6wlSDKSyF+uDfKKM+F7iCLeGEKgO/BwOHLM40vhp54zfJHm4ImVplA== X-Google-Smtp-Source: AGHT+IGTtc+zu2gf96j2XzZtPAN4Z0NM3GV9KP/mK6qNY0BoB+25nKCm2V4aBJJ1VzYvsPCQeBJe X-Received: by 2002:a17:906:3a8d:b0:a59:ad2b:ec95 with SMTP id a640c23a62f3a-a5a2d67e2c0mr1191392866b.67.1715907181799; Thu, 16 May 2024 17:53:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715907181; cv=pass; d=google.com; s=arc-20160816; b=F6Pg2ENL1VHVVe8kqgJMFD3zTRc9KMc88ciOcUQd1sy5SZGxwRC/fOrrhbdey0sV3t nI0UYCaQifGXJLWEMA0AyxTjeJBTQIqsROT0HLh7Ev55TF7PdnHgnlhgvZzUG4tkQgIV fIWZgqNyV4WRWWtTAjqKgcK7/367eTc9gQ4g3OpRJ4Y55fMNtsDiWPvXqteu8MmFF3BR qz68Mx4KRRi4lfZGQgIVB8PZvoytjmL4m8jDb/P+IJ7Hkj8Y5KngUu+OhQv9T81FhCZf BSlJj/tb6qfpkEzfz9uTgDQ149rYyTwbRcHhb0b5+CMdrsP785zroLp2dA++BCTVBVjl WBrw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:message-id:in-reply-to:subject:cc:to:from :date:dkim-signature; bh=EtLKYhkm0Hc83UgMOqwRmWSBMblrK4sok4P/PWlh6pk=; fh=05Mf2XqZWbHoG8iBWtLxMeo+GR1Zzs7L5s5FwdVkdmc=; b=asQFRlEohKt6JlzPappv3oLL6yy44R2GENQS2EPP+T47CDU7a7PZTYiT23MhhOJY3H /MwmeOkPfxPus9YZ4zjp7PN+u/zFMK1ilMjtnuLEg91oWsL4O4XEz6GMoM2uqj5b7NTz v0U3Hjl9tRMJ6fYx295qKIfrX1gBzqO98e27jcwUfYTju+ltc9zF+SzQgVCapqk0YOw8 aVXl1H7FJbSjvTHzP8ld0/suShaIeRYDrdt+C+wjJJtPhVMXxZXUCNvwEM8hrH6NFpjK uc4xCnFcgU0xyVHp1va/k2nFBFNfvhZq5gNhLJInnrxbKbjemGfHgAHg/FQnQthEZ415 Tlog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gvKGGnuy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181662-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5a17945d18si871288066b.186.2024.05.16.17.53.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 17:53:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=gvKGGnuy; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181662-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181662-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5D21E1F22B9C for ; Fri, 17 May 2024 00:53:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 62959817; Fri, 17 May 2024 00:52:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="gvKGGnuy" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 78FA5622 for ; Fri, 17 May 2024 00:52:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715907174; cv=none; b=dZAxLaLzdfynGOjS+pGWcFkAy66QzGFlI1AjKQ9EUnQQaW+YaK6Dn7IhND9QcLOAB3gIycJTETBNF6seCnBr/b0JebzuuVYarFC4ovooBRytv/LZxhC2skZ8a2DIw6ca3t0MO2nyrZWiujcrDZDiFLX2KLHRtPLv+UHEHQz4/ag= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715907174; c=relaxed/simple; bh=TegGSMyB0JVbO6jlmENdPDoxx20cRA2GXqpfoyUXYVk=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=FdRy1f6zjINYG8kpiyLyErjRJXdWAEpbtdc2v2xZvrQParnHV2ICZdXeDPDNuBdvIT+URFCAJlCK088v7C7u/P/KMvBD1LUjl0yJAsLpH6G9gljhmGEQDKajWqX4saE5kAPXm2ZsoRZ/6Fjr0EQ5VUXtBXaHqCIHrSS+r3ejjjg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gvKGGnuy; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10DAFC113CC; Fri, 17 May 2024 00:52:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715907174; bh=TegGSMyB0JVbO6jlmENdPDoxx20cRA2GXqpfoyUXYVk=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=gvKGGnuyc4WhtBlCJuhbccSsXprf1zrb45rBV9rU6MXH0h7E4npLggND/8prIh3n5 K7JEMSUkE4XcEo4u9g1ewA+wlynihMT99qyPZB13/mfI4jbJbb9FRlpGFG5qLar9mc xyhX1+h33s9YED2fgglcV3pZkRRlJ9Uah4wjuf+dTYijQwCtoLhvOkgEg1ijMcpHnU Aw3eYvTbFutAx6hVWW6WSw3g5YI+m6riav9Jduf2VKXWM0FXSVKov2441NZOZc+FqV d//YZdCaSdsze9BwKzw6StxG7qsrDLjUg5IC/eLX6DqsARE5O5dhDY2pSkfi2leVMu YRWyR2ZHYrAqg== Date: Thu, 16 May 2024 17:52:51 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Henry Wang cc: Stefano Stabellini , xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Juergen Gross , Oleksandr Tyshchenko , Michal Orzel Subject: Re: [PATCH] drivers/xen: Improve the late XenStore init protocol In-Reply-To: <028f29be-0393-4a57-83e2-ea27fe0320d5@amd.com> Message-ID: References: <20240515014330.1044617-1-xin.wang2@amd.com> <028f29be-0393-4a57-83e2-ea27fe0320d5@amd.com> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-217339045-1715907173=:2544314" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-217339045-1715907173=:2544314 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT On Thu, 16 May 2024, Henry Wang wrote: > Hi Stefano, > > On 5/16/2024 6:30 AM, Stefano Stabellini wrote: > > On Wed, 15 May 2024, Henry Wang wrote: > > > 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() and xenbus_probe() to select the code > > > path of doing the late XenStore init protocol or not. > > > > > > Take the opportunity to enhance the check of the allocated XenStore > > > interface can be properly mapped, and return error early if the > > > memremap() fails. > > > > > > Signed-off-by: Henry Wang > > > Signed-off-by: Michal Orzel > > Please add a Fixes: tag > > Sure. Will do. > > > > --- > > > drivers/xen/xenbus/xenbus_probe.c | 21 ++++++++++++++++----- > > > 1 file changed, 16 insertions(+), 5 deletions(-) > > > > > > diff --git a/drivers/xen/xenbus/xenbus_probe.c > > > b/drivers/xen/xenbus/xenbus_probe.c > > > index 3205e5d724c8..8aec0ed1d047 100644 > > > --- a/drivers/xen/xenbus/xenbus_probe.c > > > +++ b/drivers/xen/xenbus/xenbus_probe.c > > > @@ -72,6 +72,10 @@ EXPORT_SYMBOL_GPL(xen_store_evtchn); > > > struct xenstore_domain_interface *xen_store_interface; > > > EXPORT_SYMBOL_GPL(xen_store_interface); > > > +#define XS_INTERFACE_READY \ > > > + ((xen_store_interface != NULL) && \ > > > + (xen_store_interface->connection == XENSTORE_CONNECTED)) > > > + > > > enum xenstore_init xen_store_domain_type; > > > EXPORT_SYMBOL_GPL(xen_store_domain_type); > > > @@ -751,9 +755,10 @@ static void xenbus_probe(void) > > > { > > > xenstored_ready = 1; > > > - if (!xen_store_interface) { > > > - xen_store_interface = memremap(xen_store_gfn << > > > XEN_PAGE_SHIFT, > > > - XEN_PAGE_SIZE, MEMREMAP_WB); > > > + if (!xen_store_interface || XS_INTERFACE_READY) { > > > + if (!xen_store_interface) > > These two nested if's don't make sense to me. If XS_INTERFACE_READY > > succeeds, it means that ((xen_store_interface != NULL) && > > (xen_store_interface->connection == XENSTORE_CONNECTED)). > > > > So it is not possible that xen_store_interface == NULL immediately > > after. Right? > > I think this is because we want to free the irq for the late init case, > otherwise the init-dom0less will fail. For the xenstore PFN allocated case, > the connection is already set to CONNECTED when we execute init-dom0less. But > I agree with you, would below diff makes more sense to you? > > diff --git a/drivers/xen/xenbus/xenbus_probe.c > b/drivers/xen/xenbus/xenbus_probe.c > index 8aec0ed1d047..b8005b651a29 100644 > --- a/drivers/xen/xenbus/xenbus_probe.c > +++ b/drivers/xen/xenbus/xenbus_probe.c > @@ -76,6 +76,8 @@ EXPORT_SYMBOL_GPL(xen_store_interface); >         ((xen_store_interface != NULL) && \ >          (xen_store_interface->connection == XENSTORE_CONNECTED)) > > +static bool xs_late_init = false; > + >  enum xenstore_init xen_store_domain_type; >  EXPORT_SYMBOL_GPL(xen_store_domain_type); > > @@ -755,7 +757,7 @@ static void xenbus_probe(void) >  { >         xenstored_ready = 1; > > -       if (!xen_store_interface || XS_INTERFACE_READY) { > +       if (xs_late_init) { >                 if (!xen_store_interface) >                         xen_store_interface = memremap(xen_store_gfn << I would just remove the outer 'if' and do this: if (!xen_store_interface) xen_store_interface = memremap(xen_store_gfn << XEN_PAGE_SHIFT, XEN_PAGE_SIZE, MEMREMAP_WB); /* * 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. */ if (xs_init_irq > 0) free_irq(xs_init_irq, &xb_waitq); I think this should work fine in all cases. I am unsure if xs_init_irq==0 is possible valid value for xs_init_irq. If it is not, then we are fine. If 0 is a possible valid irq number, then we should initialize xs_init_irq to -1, and here check for xs_init_irq >= 0. --8323329-217339045-1715907173=:2544314--