Received: by 2002:ab2:7a09:0:b0:1f8:46dc:890e with SMTP id k9csp309877lqo; Wed, 15 May 2024 15:40:48 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVYkq1FX6PlmAK94gEiMpGm+nXl0XgDg5H5vjk8o2np3X9bOh/HjM686A3f0UiWy/+r9JdvnPj1mOlJkpjcOuYNMlcHRDG/eUjwaUGMWA== X-Google-Smtp-Source: AGHT+IFEhEkLsfF/rkshxL2LjGwFm6KzAhHjRWgLO3uAMFElmLqBY7Y93f5U3NhmdsQ6xDnFMNqo X-Received: by 2002:a05:6358:988d:b0:17c:263a:5b8e with SMTP id e5c5f4694b2df-193baf01ae1mr1721236755d.14.1715812848243; Wed, 15 May 2024 15:40:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715812848; cv=pass; d=google.com; s=arc-20160816; b=MKdKUH2vMOnwAk3Sni3GiSmkP58GvnAiyfH/OJFoDVICZ6s0WHo6ohdimD+lCJuLSC ZHqD88GYGTDO/nER1kpJTcRa6f5pEU8nXfWsSKmTC4HC4BqxcDJVQ9zQa0qOXjm6irru yEshdzYJlWbLI5AAyKL0W8GudAVGpBGkt1UaxJvo9OoheU9mGyV869PMq3GurBA2kArk cORiKNY8thK5LTSvjiACsnCCMMjjAhjkEpL9d5mzDS00R855Go0HGkWXpsheo6cBHijY O6B8wNLOn8OzV9hVpTnDpN/1DDdskxd6jrftnCrr6DGxLelqD+lD3gldI1SRcPEh6wWj 32JQ== 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=gKL3fLgpawmZWQ7L29ehRWpxdIR3W+T+D+Z57tWBxDM=; fh=1vXiDLt9Uk8+sYre9DUkJYNY+0B89oBb0PbixjhOXmc=; b=nXZ7t/rs9CLvF5Ia9k2Zj0ucQRB49XLT624HN+APCqZTKTbUhY6eqpdwnORal4bItK VOhYxgjRnx+MeUHUedz2B2aRDki86lmAElmcTGuLai7U3T7IHMbinOsNhzx9PgryikXs IhC/WKsaXaLOmMVl+RCoJjlXtLGuhFx11zsR199CdaMqG+WXGFPo2alhNmaQhh6S9C2y OdylRqADnskG46NG9jPLCT/K7dcZ0XwIKF2AhcDYsftsSXxaYKfpvSpBc1XgLrQzPdAf qZtV5SSKF7IA+0SO0V/k0BDIMmiNXFubdxBXIJ1lWeCcZjxhQYYfHDEHYHXXmUIwvYTx jipw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DC2NxJVE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-180446-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180446-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 41be03b00d2f7-634103f7243si13951675a12.296.2024.05.15.15.40.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 May 2024 15:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-180446-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=DC2NxJVE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-180446-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-180446-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 404742849EE for ; Wed, 15 May 2024 22:30:43 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 623433C460; Wed, 15 May 2024 22:30:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DC2NxJVE" 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 7C3CF2A8D7 for ; Wed, 15 May 2024 22:30:37 +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=1715812237; cv=none; b=h2zMADEMMyQdEHIWouLD0dM2vwUZbO40KRqh7C2MlhSdJCeEf2YcTW4dpN/amYr6GH12AlLY87ooR9sRg84Ln84nFa3l58ffgs4NcyOKWA/m+ntyg2GZjSvEW8+ninrIusJykZHCo5dXeSJYwoGWK7iCrzM1c7d5MXV520iKxKw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715812237; c=relaxed/simple; bh=BhaxKrSJ2V074gHXzgPwRKtFyji5OeLt5R3Sl21D4t0=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=iutCIJLWgROsFN4a6brlrBp3ZengIrPdVjimT79LbVTgxqsKWqfG3FyulPAIaXOqvLoZvzSHnh64/ZBu7BQPX8M2LOUiEqc0ytUCdrYgMiwxSPKq847lco7oFg897cEE9u3GZ9P3mL/uBbXT4N9U+4F+P36IOpU1bwcaTYlU6aU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DC2NxJVE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3D22C116B1; Wed, 15 May 2024 22:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1715812237; bh=BhaxKrSJ2V074gHXzgPwRKtFyji5OeLt5R3Sl21D4t0=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=DC2NxJVEy31yOLjZq9huooHYPwBBmjBjscRNb0ZIy3x6OEpnlOzGNuQT92ALOTRRV 1NNhrZjfbKC0lEtLDZOmnnkdgi080nHff9IsAxUVb/vA1ieHqy5fJddxyiP7BlRu07 HG78AuDwrZh9dO0iHbi3gN/jF1hi1vGY/F/9TLhql3jUuWpIr9rRHNB99sBSVcfHte 0joH++aTxyWzb7rwjAJ0PSCxJrYrGnt6ObW8dQm/61+/4UlfEcEzW7mcCJgjOv2vxt OcBtySvKnw9a3yyXI8RbwBEuusgl/lGV/8pqUE8U0okm/NYcsTjYEWnd+a8Bzvuj3M kdb3NJxOwTmtg== Date: Wed, 15 May 2024 15:30:34 -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] drivers/xen: Improve the late XenStore init protocol In-Reply-To: <20240515014330.1044617-1-xin.wang2@amd.com> Message-ID: References: <20240515014330.1044617-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 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 > --- > 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? > + 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 > @@ -822,7 +827,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 +836,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 +1019,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 = -ENOMEM; I think this should -EINVAL > + goto out_error; > + } > if (xen_store_interface->connection != XENSTORE_CONNECTED) > wait = true; > } > -- > 2.34.1 >