All of lore.kernel.org
 help / color / mirror / Atom feed
From: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
To: Mykola Kvach <xakep.amatop@gmail.com>
Cc: "Luca Fancellu" <Luca.Fancellu@arm.com>,
	"xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
	"Mykola Kvach" <Mykola_Kvach@epam.com>,
	"Stefano Stabellini" <sstabellini@kernel.org>,
	"Julien Grall" <julien@xen.org>,
	"Bertrand Marquis" <Bertrand.Marquis@arm.com>,
	"Michal Orzel" <michal.orzel@amd.com>,
	"Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Anthony PERARD" <anthony.perard@vates.tech>,
	"Jan Beulich" <jbeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>,
	"Rahul Singh" <Rahul.Singh@arm.com>
Subject: Re: [PATCH v8 13/13] xen/arm: Add support for system suspend triggered by hardware domain
Date: Thu, 7 May 2026 22:25:46 +0000	[thread overview]
Message-ID: <87lddusvpy.fsf@epam.com> (raw)
In-Reply-To: <CAGeoDV8WkRGubF0qEXd4+PsXuabz3914G7bTYxTbaxZ2DsnY6w@mail.gmail.com>	(Mykola Kvach's message of "Tue, 5 May 2026 23:34:18 +0300")

Hi Mykola,

Mykola Kvach <xakep.amatop@gmail.com> writes:

[...]

>> > +    status = can_system_suspend();
>> > +    if ( status )
>> > +    {
>> > +        system_state = SYS_STATE_resume;
>> > +        goto resume_scheduler;
>>
>> When we have an error and we get the resume_scheduler path, we apply back the
>> context of the guest saved previously in do_psci_1_0_system_suspend(), so am I
>> correct saying the guest won’t get any PSCI error back and we resume the guest
>> from the guest resume entrypoint?
>>
>> In case, should we have a different path that returns a PSCI error (PSCI_*) into the guest
>> x0, and skips the context restore?
>
> You are right about the current control flow: once the virtual
> SYSTEM_SUSPEND request has been accepted and the domain has been parked, a
> later failure in the Xen-wide suspend path resumes the domain through the normal
> domain resume path, rather than returning a PSCI error from the original call.
>
> This is intentional in the current design. The virtual PSCI SYSTEM_SUSPEND
> path parks the domain and saves its resume context. The actual Xen-wide host
> suspend is a separate step that is attempted only after all domains are
> suspended.
>
> So a failure in the later Xen-wide suspend step is treated as an abort of the
> host suspend attempt after the domain suspend was already accepted. The domain
> is then resumed through the existing domain resume path, similarly to the
> toolstack/xl suspend-resume flow, rather than by re-entering the guest PSCI
> call path and modifying the saved vCPU context again.
>
> I agree this design is not obvious from the patch. I will clarify the commit
> message and comments. If you or the maintainers think that failures before the
> physical SYSTEM_SUSPEND call succeeds should be reported back through the
> original virtual PSCI call, then this would require a different flow. I was
> trying to avoid that extra complexity in this series.

I think that there is no sense to reporting an error back to guest. PSCI
allows resume at any stage, so it is acceptable to have such brief "suspend"

>
>>
>> > +    }
>> > +
>> > +    /*
>> > +     * Non-boot CPUs have to be disabled on suspend and enabled on resume
>> > +     * (hotplug-based mechanism). Disabling non-boot CPUs will lead to PSCI
>> > +     * CPU_OFF to be called by each non-boot CPU. Depending on the underlying
>> > +     * platform capabilities, this may lead to the physical powering down of
>> > +     * CPUs.
>> > +     */
>> > +    status = disable_nonboot_cpus();
>> > +    if ( status )
>> > +    {
>> > +        system_state = SYS_STATE_resume;
>> > +        goto resume_nonboot_cpus;
>> > +    }
>> > +
>> > +    time_suspend();
>> > +
>> > +    status = iommu_suspend();
>> > +    if ( status )
>> > +    {
>> > +        system_state = SYS_STATE_resume;
>> > +        goto resume_time;
>> > +    }
>> > +
>> > +    console_start_sync();
>> > +    status = console_suspend();
>> > +    if ( status )
>> > +    {
>> > +        dprintk(XENLOG_ERR, "Failed to suspend the console, err=%d\n", status);
>> > +        system_state = SYS_STATE_resume;
>> > +        goto resume_end_sync;
>> > +    }
>> > +
>> > +    local_irq_save(flags);
>> > +    status = gic_suspend();
>> > +    if ( status )
>> > +    {
>> > +        system_state = SYS_STATE_resume;
>> > +        goto resume_irqs;
>> > +    }
>> > +
>> > +    set_init_ttbr(xen_pgtable);
>> > +
>> > +    /*
>> > +     * Enable identity mapping before entering suspend to simplify
>> > +     * the resume path
>> > +     */
>> > +    update_boot_mapping(true);
>> > +
>> > +    if ( prepare_resume_ctx(&cpu_context) )
>> > +    {
>> > +        status = call_psci_system_suspend();
>> > +        /*
>> > +         * If suspend is finalized properly by above system suspend PSCI call,
>> > +         * the code below in this 'if' branch will never execute. Execution
>> > +         * will continue from hyp_resume which is the hypervisor's resume point.
>> > +         * In hyp_resume CPU context will be restored and since link-register is
>> > +         * restored as well, it will appear to return from prepare_resume_ctx.
>> > +         * The difference in returning from prepare_resume_ctx on system suspend
>> > +         * versus resume is in function's return value: on suspend, the return
>> > +         * value is a non-zero value, on resume it is zero. That is why the
>> > +         * control flow will not re-enter this 'if' branch on resume.
>> > +         */
>> > +        if ( status )
>> > +            dprintk(XENLOG_WARNING, "PSCI system suspend failed, err=%d\n",
>> > +                    status);
>> > +    }
>> > +
>> > +    system_state = SYS_STATE_resume;
>> > +    update_boot_mapping(false);
>> > +
>> > +    gic_resume();
>> > +
>> > + resume_irqs:
>> > +    local_irq_restore(flags);
>> > +
>> > +    console_resume();
>> > + resume_end_sync:
>> > +    console_end_sync();
>> > +
>> > +    iommu_resume();
>> > +
>> > + resume_time:
>> > +    time_resume();
>> > +
>> > + resume_nonboot_cpus:
>> > +    /*
>> > +     * The rcu_barrier() has to be added to ensure that the per cpu area is
>> > +     * freed before a non-boot CPU tries to initialize it (_free_percpu_area()
>> > +     * has to be called before the init_percpu_area()). This scenario occurs
>> > +     * when non-boot CPUs are hot-unplugged on suspend and hotplugged on resume.
>> > +     */
>> > +    rcu_barrier();
>> > +    enable_nonboot_cpus();
>> > +
>> > + resume_scheduler:
>> > +    scheduler_enable();
>> > +    thaw_domains();
>> > +
>> > +    system_state = SYS_STATE_active;
>> > +
>> > +    printk("Resume (status %d)\n", status);
>> > +
>> > +    domain_resume(d);
>> > +}
>> > +
>> > +static DECLARE_TASKLET(system_suspend_tasklet, system_suspend, NULL);
>> > +
>> > +void host_system_suspend(struct domain *d)
>> > +{
>> > +    system_suspend_tasklet.data = (void *)d;
>> > +    /*
>> > +     * The suspend procedure has to be finalized by the pCPU#0 (non-boot pCPUs
>> > +     * will be disabled during the suspend).
>> > +     */
>> > +    tasklet_schedule_on_cpu(&system_suspend_tasklet, 0);
>> > +}
>> > +
>> > /*
>> >  * Local variables:
>> >  * mode: C
>> > diff --git a/xen/arch/arm/vpsci.c b/xen/arch/arm/vpsci.c
>> > index bd87ec430d..8fb9172186 100644
>> > --- a/xen/arch/arm/vpsci.c
>> > +++ b/xen/arch/arm/vpsci.c
>> > @@ -5,6 +5,7 @@
>> >
>> > #include <asm/current.h>
>> > #include <asm/domain.h>
>> > +#include <asm/suspend.h>
>> > #include <asm/vgic.h>
>> > #include <asm/vpsci.h>
>> > #include <asm/event.h>
>> > @@ -232,8 +233,7 @@ static int32_t do_psci_1_0_system_suspend(register_t epoint, register_t cid)
>> >     if ( is_64bit_domain(d) && is_thumb )
>> >         return PSCI_INVALID_ADDRESS;
>> >
>> > -    /* SYSTEM_SUSPEND is not supported for the hardware domain yet */
>> > -    if ( is_hardware_domain(d) )
>> > +    if ( !IS_ENABLED(CONFIG_SYSTEM_SUSPEND) && is_hardware_domain(d) )
>> >         return PSCI_NOT_SUPPORTED;
>> >
>> >     /* Ensure that all CPUs other than the calling one are offline */
>> > @@ -266,6 +266,9 @@ static int32_t do_psci_1_0_system_suspend(register_t epoint, register_t cid)
>> >             "SYSTEM_SUSPEND requested, epoint=%#"PRIregister", cid=%#"PRIregister"\n",
>> >             epoint, cid);
>> >
>> > +    if ( is_control_domain(d) )
>>
>> Why is_control_domain() here and not is_hardware_domain() ?
>
> The use of is_control_domain() is intentional.
>
> The intended model is that Xen-wide host suspend is orchestrated by the
> privileged management/control domain. The control domain coordinates the
> toolstack side, asks other domains to enter suspend, and then issues the final
> SYSTEM_SUSPEND request to Xen.
>
> This does not have to be the same entity as the hardware domain. If the
> hardware domain is separate, it is one of the domains that the control domain
> parks before the final host suspend step.
>
> The hwdom-specific checks in this patch have a different purpose: they avoid
> the old hwdom_shutdown() path for SHUTDOWN_suspend and allow the hardware
> domain to be parked as part of the suspend sequence. They do not define the
> policy for who is allowed to trigger Xen-wide host suspend.
>
> That said, this policy may not be optimal for all configurations, especially
> when the control and hardware domain roles are split. I would appreciate your
> view, as well as the maintainers' views, on whether the trigger should remain
> control-domain based, be tied to the hardware domain instead, or be expressed
> through a separate host-suspend capability/helper.


Hardware domain owns all the hardware. Hardware shall be put to
power-down/suspended state before suspending the SoC, so it can be
resumed afterwards. You can't just pause hardware domain in the same way
as pausing all other domains.

(Of course, we'll have the same issues with domain that have
passed-through hardware, but in this case Dom0 shall orchestrate proper
suspend sequence for these)

[...]

-- 
WBR, Volodymyr

  reply	other threads:[~2026-05-07 22:26 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-02 10:45 [PATCH v8 00/13] Add initial Xen Suspend-to-RAM support on ARM64 Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 01/13] xen/arm: Add suspend and resume timer helpers Mykola Kvach
2026-04-20 15:22   ` Luca Fancellu
2026-04-02 10:45 ` [PATCH v8 02/13] xen/arm: gic-v2: Implement GIC suspend/resume functions Mykola Kvach
2026-04-21 13:24   ` Luca Fancellu
2026-05-07  7:48     ` Mykola Kvach
2026-05-08 10:56       ` Luca Fancellu
2026-05-10  6:02         ` Mykola Kvach
2026-05-11  6:40           ` Luca Fancellu
2026-05-11 20:41             ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 03/13] xen/arm: gic-v3: tolerate retained redistributor LPI state across CPU_OFF Mykola Kvach
2026-04-22 15:55   ` Luca Fancellu
2026-05-05  6:06     ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 04/13] xen/arm: gic-v3: Implement GICv3 suspend/resume functions Mykola Kvach
2026-04-23 11:28   ` Luca Fancellu
2026-05-05  7:26     ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 05/13] xen/arm: gic-v3: add ITS suspend/resume support Mykola Kvach
2026-04-24 10:53   ` Luca Fancellu
2026-05-05 10:09     ` Mykola Kvach
2026-05-08 11:30       ` Luca Fancellu
2026-05-08 22:11         ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 06/13] xen/arm: tee: keep init_tee_secondary() for hotplug and resume Mykola Kvach
2026-04-24 10:59   ` Luca Fancellu
2026-04-27  8:19   ` Bertrand Marquis
2026-05-07 22:26   ` Volodymyr Babchuk
2026-04-02 10:45 ` [PATCH v8 07/13] xen/arm: ffa: fix notification SRI across CPU hotplug/suspend Mykola Kvach
2026-04-24 12:05   ` Luca Fancellu
2026-04-27  8:20   ` Bertrand Marquis
2026-05-05 10:18     ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 08/13] iommu/ipmmu-vmsa: Implement suspend/resume callbacks Mykola Kvach
2026-04-24 13:34   ` Luca Fancellu
2026-05-05 11:45     ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 09/13] arm/smmu-v3: add suspend/resume handlers Mykola Kvach
2026-04-27 14:01   ` Luca Fancellu
2026-04-27 14:02   ` Luca Fancellu
2026-05-05 15:23     ` Mykola Kvach
2026-05-08 12:21       ` Luca Fancellu
2026-05-08 21:44         ` Mykola Kvach
2026-05-09  7:50           ` Luca Fancellu
2026-04-02 10:45 ` [PATCH v8 10/13] xen/arm: Resume memory management on Xen resume Mykola Kvach
2026-04-27 14:50   ` Luca Fancellu
2026-05-05 15:55     ` Mykola Kvach
2026-05-08 13:26       ` Luca Fancellu
2026-05-08 20:51         ` Mykola Kvach
2026-05-07 22:06   ` Volodymyr Babchuk
2026-05-08 20:59     ` Mykola Kvach
2026-05-11 16:11       ` Oleksandr Tyshchenko
2026-04-02 10:45 ` [PATCH v8 11/13] xen/arm: Save/restore context on suspend/resume Mykola Kvach
2026-04-27 15:26   ` Luca Fancellu
2026-05-07 22:17   ` Volodymyr Babchuk
2026-05-08 10:38     ` Mykola Kvach
2026-05-11 16:00   ` Oleksandr Tyshchenko
2026-05-11 18:52     ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 12/13] xen/arm: Implement PSCI SYSTEM_SUSPEND call (host interface) Mykola Kvach
2026-04-27 16:21   ` Luca Fancellu
2026-05-05 16:15     ` Mykola Kvach
2026-04-02 10:45 ` [PATCH v8 13/13] xen/arm: Add support for system suspend triggered by hardware domain Mykola Kvach
2026-04-02 11:00   ` Jan Beulich
2026-04-29  8:05   ` Luca Fancellu
2026-05-05 20:34     ` Mykola Kvach
2026-05-07 22:25       ` Volodymyr Babchuk [this message]
2026-05-08  8:37         ` Mykola Kvach
2026-05-08 14:30       ` Luca Fancellu
2026-05-08 20:49         ` Mykola Kvach
2026-04-16 12:51 ` PING: Re: [PATCH v8 00/13] Add initial Xen Suspend-to-RAM support on ARM64 Mykola Kvach
2026-04-16 12:52 ` Mykola Kvach

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87lddusvpy.fsf@epam.com \
    --to=volodymyr_babchuk@epam.com \
    --cc=Bertrand.Marquis@arm.com \
    --cc=Luca.Fancellu@arm.com \
    --cc=Mykola_Kvach@epam.com \
    --cc=Rahul.Singh@arm.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=anthony.perard@vates.tech \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=michal.orzel@amd.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=xakep.amatop@gmail.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.