[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] xen/domain: make shutdown state explicit


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Mykola Kvach <xakep.amatop@xxxxxxxxx>
  • Date: Wed, 3 Jun 2026 09:46:39 +0300
  • Arc-authentication-results: i=1; mx.google.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=7dBaqWYLvzEH6qwxN/EwADTUjkGEkjcWDh2cRodeWNI=; fh=V4JwZlQFNRYiaNJa0y1s6t2uNB0wWRvWPMwApFIm7J0=; b=krHhfWKMMPWJ+yhfTQoYpRASpoEyMjm6HwuoIR14bxSuTZf62Wvkn8EwVaB1oVlcu+ GNAi9YtgZgu6X1t1rV8+yDa2b5Zp1l4y9BSY3xgy9qTTsg4juVKSEKgZ5WNKaDHaLlHL ZfRZ3MQ+fJh0trXLdaDZRSBdpSzeLL0soWmFEqBiB5psnx8GQgWYLz/BPK7K6M3WH2o5 kIATJQLTPX9MXd5kSZwPk5z3aBJ/M36PTKRhzafSv8xNcdSARa9kX/QIIaqXmQQh6gu2 eHvZK9AAA/ajrcXwnlAooET26yFGhm7MnNAZGFLgjSX3gd7GvTeL56C5jN0PnlBqhoUF aiFw==; darn=lists.xenproject.org
  • Arc-seal: i=1; a=rsa-sha256; t=1780469212; cv=none; d=google.com; s=arc-20240605; b=jk2WiSg7R4GeG10AwjzZQA4Ved7fxirTEQOOyXfuAkgmKppZfYRguW6J/+1WvCUxos FtQJVsJKVa2uv8DZGFg1lJ8DBepu3Myk17ZAI0ayQXe3Vc8LLVOhyZSC+KTZr1vDQxNw zax7XymG9QlkERaLLYsVSvp+REm2BywAhYMtRmAtP9ibj+9ILBTRoJMSakZad4Idk6u3 x0okiRwt+ICmONJAnwA6qEPbBJy5V9OEEHNUI+JDsVBsSm5XfO0pSMLKcmJM7cwg1cNZ I/r0UVzD+GV9qJzHcWVZRGkvug0xpP/PgGw19Tt8Ds1NT5Q/DyYvWzVV6HYMIEKYt8CO 6WdQ==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=20251104 header.d=gmail.com header.i="@gmail.com" header.h="Content-Transfer-Encoding:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References:MIME-Version"
  • Cc: Mykola Kvach <mykola_kvach@xxxxxxxx>, Paul Durrant <paul@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Tim Deegan <tim@xxxxxxx>, Dario Faggioli <dfaggioli@xxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, George Dunlap <gwd@xxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • Delivery-date: Wed, 03 Jun 2026 06:47:09 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

Hi Jan,

On Wed, Apr 8, 2026 at 4:06 PM Jan Beulich <jbeulich@xxxxxxxx> wrote:
>
> On 01.04.2026 08:41, Mykola Kvach wrote:
> > From: Mykola Kvach <mykola_kvach@xxxxxxxx>
> >
> > The shutdown flow currently overloads is_shutting_down and
> > is_shut_down to represent multiple phases of the shutdown lifecycle.
> > Some users treat is_shutting_down narrowly as "shutdown still needs to
> > be driven to completion", while others rely on it more broadly as
> > "the domain is no longer in its normal running state".
> >
> > Make the lifecycle explicit by introducing enum
> > domain_shutdown_state and helper predicates whose names match their
> > semantics: domain_shutting_down() for the transient phase,
> > domain_shutdown_completed() for the final state, and
> > domain_in_shutdown_state() for checks that need the union of both.
> >
> > The conversion is intentionally not mechanical. The old flags were not
> > mutually exclusive: once a domain became fully shut down,
> > is_shutting_down remained set. As a result, sites that previously
> > used the absence of is_shutting_down to exclude both the transient and
> > completed states now use domain_in_shutdown_state(), sites that care
> > specifically about the final state use domain_shutdown_completed(),
> > and only paths that still have work to do before shutdown finalization
> > use domain_shutting_down().
>
> In how far is the distinction between domain_shutting_down() and
> domain_in_shutdown_state() really necessary? What you describe above
> still leaves me pretty clueless as to almost(?) all of the uses of the
> latter (where I think the former could be used just as well). Many
> paths simply can't be taken anymore for a fully shut down domain, so
> the distinction between the two is moot there.
>
> I'm also concerned of the name domain_in_shutdown_state() itself. To
> me this is far closer to domain_shutdown_completed() than to the union
> of both states. See how e.g. x86 CPUs can be "in shutdown state", i.e.
> not responding to anything but a reset or init signal.
>
> IOW an entirely mechanical replacement might in fact be easier to look
> at. And in the one rare case where the distinction might indeed be
> relevant, "domain_shutting_down() || domain_shutdown_completed()" could
> be used.
>
> > @@ -1423,9 +1423,12 @@ int domain_shutdown(struct domain *d, u8 reason)
> >      return 0;
> >  }
> >
> > -void domain_resume(struct domain *d)
> > +int domain_resume(struct domain *d)
> >  {
> >      struct vcpu *v;
> > +    enum domain_shutdown_state shutdown_state;
> > +    unsigned int shutdown_code;
> > +    int rc = 0;
> >
> >      /*
> >       * Some code paths assume that shutdown status does not get reset under
> > @@ -1435,10 +1438,18 @@ void domain_resume(struct domain *d)
> >
> >      spin_lock(&d->shutdown_lock);
> >
> > -    d->is_shutting_down = d->is_shut_down = 0;
> > +    shutdown_state = d->shutdown_state;
> > +    shutdown_code = d->shutdown_code;
> > +
> > +    if ( !domain_shutdown_completed(d) )
> > +    {
> > +        rc = -EINVAL;
> > +        goto out_unlock;
> > +    }
>
> I can't help the impression that you're mixing two things here - adjustment
> to how shutdown state is tracked, and enforcement of completed shutdown
> right here. This separate change likely would better be split out, and then
> come with a description saying not only what is being changed, but also why,
> and why the change is correct for both call sites.

In v3 I have dropped this part, so the patch no longer changes
domain_resume() behaviour or its callers. domain_resume() remains void,
and the patch only makes the existing shutdown state tracking explicit.

One follow-up question about the dropped change: do you think resume-state
validation would be worth pursuing separately?

AFAICT, soft reset already has its own DOMCTL path, so I do not mean to treat
XEN_DOMCTL_resumedomain as a soft-reset interface. The distinction I had in
mind is rather that we may want different validation rules for the generic
resume helper and for a resume-from-suspend path. In particular, soft reset
could keep the current semantics, while a resume-from-suspend path would only
clear the shutdown state if the domain had previously entered suspend.

If this distinction makes sense, I can look into it as a separate patch with
its own justification for the affected call sites. Otherwise I will leave it
out.

Best regards,
Mykola



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.