Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp647325lqo; Thu, 16 May 2024 18:22:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUeACddTz6QyQ34bfaPdZVdW10LG4z8RFskePPpcct8pJkHY+ZneZQwUZL/jnieJnaoC0ZHQPEIqvO2ii0Gvv0wHANUmsGLwvFRwRGRuA== X-Google-Smtp-Source: AGHT+IE10HM+1h3Wr9B1Z6FiDcVvJ3n9lzqBJnbk04SHPeoS7qPgDFG6mWs5KO2twIInsp5cVU7p X-Received: by 2002:a05:6870:b1c4:b0:239:c981:cfb4 with SMTP id 586e51a60fabf-241728f4e6amr22988524fac.12.1715908925491; Thu, 16 May 2024 18:22:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715908925; cv=pass; d=google.com; s=arc-20160816; b=oCjjWkFNOl+Fl+JcCYg/GJBkSjFZaWj1zeAozBBPRVmipBegR9Lrvwhfwz/d5MEjKC 1siojuSm1JHl3gdufDCAaGT9dQkVwgT7CIKsntDBr1u4cgsmlxW7xxueEyeLIe8cjjZl 7gz/7gKtKGu5Xc6WgpPYXrT8NC/F0ewnJGm7jSaa0cyGfMNptlQWXiXwy6L/5mb2Qidz 9WJLQOTOEnE+6IOX85uyQLvWlA+uqnXcRS1l38PJa8WE4hV7wjG1NYvrP3PN1/9ZxTT1 u3vXTTx/JqACJdUccvzpxSOroN4dDMQJdP8wYq0TfcF/zuoDbIrhVkjWsMgAs1M+CMQ6 fygg== 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=Dqp0GmqtP5pwmtQOHTktvPurBw4bu2xZ2GzgNSx90lA=; fh=1vXiDLt9Uk8+sYre9DUkJYNY+0B89oBb0PbixjhOXmc=; b=eA2DrV23zJu9DaVfubABhYLKkTOmUVuUZI3rXMm9y7iQe8vgqFORcJwfdE57gUtvx3 LprJZ6KNLAQ+7niYe0GmsG5ISsCdU27CRWDV/oZJyxOTTBfqjTfc9pk+x/SvdEhdyu2v 3TehmWmSNPmNWlDqLx1wuLNFuHWdVgeV/cU1280KbndLAZhBiFZeryBgbXcmncCZfSou BO1qyp3ARbVHu9CpLCH/pt6nwf3AD4CvZNWh45omqSvfuBvi06EM1V428HD4s1foNYrA xKJQX9tksYDRAArDhT0CW3oV9Y+uBrJXFoxNuFawbnd9tg5z+HoIn0dO353qRFn4a1hr 4w7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3ModDtG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181674-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181674-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id d2e1a72fcca58-6f4d2aeeff2si16918614b3a.210.2024.05.16.18.22.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 May 2024 18:22:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-181674-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=r3ModDtG; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-181674-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-181674-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 213C1281A60 for ; Fri, 17 May 2024 01:22:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5D41ECC; Fri, 17 May 2024 01:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="r3ModDtG" 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 019D77FD for ; Fri, 17 May 2024 01:21:58 +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=1715908919; cv=none; b=C2+fHqbowviOzd31fUmr9ZGtw0E6JeDm/zy2IIeH/OXvo1+6AVE7h+f4UIjTOq3WL45GLgJ+uzt9q525oAwkqxpgZwrDVkO35K952e42EARWP14TZb4n4BVkJRr26BTyPzg5y91/P81IPr7QYdksPIBebMNfqK3dAka6mGLEg+Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715908919; c=relaxed/simple; bh=/+69Lf2vDX6gQntQK69tY9Tw2kBCjXsZWh6uIw2z2+U=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=abvZHEicut6ephaHfcq5mgyq90QwLcixS+qcb7zalpn2vQbFxpaVgf5S0BwqkwlbE01VHKuGxSSpZB1JnShQ2ldcW9I8XyP4A6EJUaCv5aBAYTCGwON/rjsshCOmzPKk1ZAccQkdYS1J/09ZRYLN/VHcnqeGmnAVTuc3BNT8aWs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r3ModDtG; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AC266C113CC; Fri, 17 May 2024 01:21:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715908918; bh=/+69Lf2vDX6gQntQK69tY9Tw2kBCjXsZWh6uIw2z2+U=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=r3ModDtGISt7KGEtcdnrchRxmpJyTWN+T77c9M9MSXgNhqXLH8SVghfzsHCafFlCW /ZeuCQb6sIYhnTfBHsbdXD7LhIS4m5p4GZBup/74EW8zjXS2FEu5HJ1Itj67uJn5N0 /8lqOxRgWaq480aacBo0ptQgOxZ4EWDAFoIhmpYpqVmw6VuQy+D3TrtGrjKPiSXWue m5ILlc8RZPTn84+hUSL7bc90XffLGR8KSlj1R/rN3OwzKYtUiypU/hablIeIkBg2Bt EUzd8SCUKtNIXcxWf16nfYF5qYEfHF/L4gnJQCEN5yXNLtrArog+9xYmC/Mh6RE6sR GtVf/nbHM6t7Q== Date: Thu, 16 May 2024 18:21:55 -0700 (PDT) From: Stefano Stabellini X-X-Sender: sstabellini@ubuntu-linux-20-04-desktop To: Henry Wang cc: xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Michal Orzel Subject: Re: [PATCH v2] drivers/xen: Improve the late XenStore init protocol In-Reply-To: <20240517011516.1451087-1-xin.wang2@amd.com> Message-ID: References: <20240517011516.1451087-1-xin.wang2@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: text/plain; charset=US-ASCII On Fri, 17 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() 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: 5b3353949e89 ("xen: add support for initializing xenstore later as HVM domain") > Signed-off-by: Henry Wang > Signed-off-by: Michal Orzel Reviewed-by: Stefano Stabellini > --- > v2: > - Use -EINVAL for the memremap() check. (Stefano) > - Add Fixes: tag. (Stefano) > - Rework the condition for free_irq() in xenbus_probe(). (Stefano) > --- > drivers/xen/xenbus/xenbus_probe.c | 36 ++++++++++++++++++++----------- > 1 file changed, 23 insertions(+), 13 deletions(-) > > diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c > index 3205e5d724c8..1a9ded0cddcb 100644 > --- a/drivers/xen/xenbus/xenbus_probe.c > +++ b/drivers/xen/xenbus/xenbus_probe.c > @@ -65,13 +65,17 @@ > #include "xenbus.h" > > > -static int xs_init_irq; > +static int xs_init_irq = -1; > int xen_store_evtchn; > 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,19 +755,19 @@ static void xenbus_probe(void) > { > xenstored_ready = 1; > > - if (!xen_store_interface) { > + 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. > - */ > + /* > + * 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); > - } > > /* > * In the HVM case, xenbus_init() deferred its call to > @@ -822,7 +826,7 @@ static int __init xenbus_probe_initcall(void) > if (xen_store_domain_type == XS_PV || > (xen_store_domain_type == XS_HVM && > !xs_hvm_defer_init_for_callback() && > - xen_store_interface != NULL)) > + XS_INTERFACE_READY)) > xenbus_probe(); > > /* > @@ -831,7 +835,7 @@ static int __init xenbus_probe_initcall(void) > * started, then probe. It will be triggered when communication > * starts happening, by waiting on xb_waitq. > */ > - if (xen_store_domain_type == XS_LOCAL || xen_store_interface == NULL) { > + if (xen_store_domain_type == XS_LOCAL || !XS_INTERFACE_READY) { > struct task_struct *probe_task; > > probe_task = kthread_run(xenbus_probe_thread, NULL, > @@ -1014,6 +1018,12 @@ static int __init xenbus_init(void) > xen_store_interface = > memremap(xen_store_gfn << XEN_PAGE_SHIFT, > XEN_PAGE_SIZE, MEMREMAP_WB); > + if (!xen_store_interface) { > + pr_err("%s: cannot map HVM_PARAM_STORE_PFN=%llx\n", > + __func__, v); > + err = -EINVAL; > + goto out_error; > + } > if (xen_store_interface->connection != XENSTORE_CONNECTED) > wait = true; > } > -- > 2.34.1 >