public inbox for qemu-devel@nongnu.org
 help / color / mirror / Atom feed
* [PATCH] migration: check is_active for old-style vmstate
@ 2026-03-11  5:16 Yanfei Xu
  2026-03-11 17:34 ` Peter Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Yanfei Xu @ 2026-03-11  5:16 UTC (permalink / raw)
  To: qemu-devel; +Cc: peterx, farosas, caixiangfeng, liwenbo.liwenbo, yanfei.xu

old-style vmstate doesn't use vmsd and instead rely on SaveStateEntry
ops. Check is_active for old-style vmstate to determine whether they
should be skipped during migration.

Signed-off-by: Yanfei Xu <yanfei.xu@bytedance.com>
---
 migration/savevm.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/migration/savevm.c b/migration/savevm.c
index 197c89e0e6..7eee83ffca 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -1030,15 +1030,27 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdesc,
                         Error **errp)
 {
     int ret;
+    const bool has_old_style = se->ops && se->ops->save_state;
 
-    if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
+    if (!has_old_style && !se->vmsd) {
         return 0;
+    } else if (has_old_style && se->vmsd) {
+        error_report("%s: '%s' (section_id=%u): unexpected: both vmsd (%s) and"
+                     " old-style save_state are set", __func__, se->idstr,
+                     se->section_id, se->vmsd->name);
+        return -EINVAL;
     }
+
     if (se->vmsd && !vmstate_section_needed(se->vmsd, se->opaque)) {
         trace_savevm_section_skip(se->idstr, se->section_id);
         return 0;
     }
 
+    if (has_old_style && se->ops->is_active && !se->ops->is_active(se->opaque)) {
+        trace_savevm_section_skip(se->idstr, se->section_id);
+        return 0;
+    }
+
     trace_savevm_section_start(se->idstr, se->section_id);
     save_section_header(f, se, QEMU_VM_SECTION_FULL);
     if (vmdesc) {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration: check is_active for old-style vmstate
  2026-03-11  5:16 [PATCH] migration: check is_active for old-style vmstate Yanfei Xu
@ 2026-03-11 17:34 ` Peter Xu
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Xu @ 2026-03-11 17:34 UTC (permalink / raw)
  To: Yanfei Xu; +Cc: qemu-devel, farosas, caixiangfeng, liwenbo.liwenbo

On Wed, Mar 11, 2026 at 01:16:58PM +0800, Yanfei Xu wrote:
> old-style vmstate doesn't use vmsd and instead rely on SaveStateEntry
> ops. Check is_active for old-style vmstate to determine whether they
> should be skipped during migration.

Would you please dscribe the use case?

We only have two users in upstream tree that provided is_active(), and
neither of them provided save_state().  IOW, so far it works kind of mutual
exclusively v.s. save_state(), afaict.

> 
> Signed-off-by: Yanfei Xu <yanfei.xu@bytedance.com>
> ---
>  migration/savevm.c | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/migration/savevm.c b/migration/savevm.c
> index 197c89e0e6..7eee83ffca 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -1030,15 +1030,27 @@ static int vmstate_save(QEMUFile *f, SaveStateEntry *se, JSONWriter *vmdesc,
>                          Error **errp)
>  {
>      int ret;
> +    const bool has_old_style = se->ops && se->ops->save_state;
>  
> -    if ((!se->ops || !se->ops->save_state) && !se->vmsd) {
> +    if (!has_old_style && !se->vmsd) {
>          return 0;
> +    } else if (has_old_style && se->vmsd) {
> +        error_report("%s: '%s' (section_id=%u): unexpected: both vmsd (%s) and"
> +                     " old-style save_state are set", __func__, se->idstr,
> +                     se->section_id, se->vmsd->name);
> +        return -EINVAL;
>      }
> +
>      if (se->vmsd && !vmstate_section_needed(se->vmsd, se->opaque)) {
>          trace_savevm_section_skip(se->idstr, se->section_id);
>          return 0;
>      }
>  
> +    if (has_old_style && se->ops->is_active && !se->ops->is_active(se->opaque)) {
> +        trace_savevm_section_skip(se->idstr, se->section_id);
> +        return 0;
> +    }
> +
>      trace_savevm_section_start(se->idstr, se->section_id);
>      save_section_header(f, se, QEMU_VM_SECTION_FULL);
>      if (vmdesc) {
> -- 
> 2.20.1
> 

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration: check is_active for old-style vmstate
@ 2026-03-12  5:25 Yanfei Xu
  2026-03-12 15:36 ` Peter Xu
  0 siblings, 1 reply; 5+ messages in thread
From: Yanfei Xu @ 2026-03-12  5:25 UTC (permalink / raw)
  To: peterx
  Cc: qemu-devel, farosas, caixiangfeng, liwenbo.liwenbo, yanfei.xu,
	isyanfei.xu

> On Wed, Mar 11, 2026 at 01:16:58PM +0800, Yanfei Xu wrote:
>>/old-style vmstate doesn't use vmsd and instead rely on SaveStateEntry/
>>/ops. Check is_active for old-style vmstate to determine whether they/
>>/should be skipped during migration./
>
> Would you please dscribe the use case?
>
> We only have two users in upstream tree that provided is_active(), and
> neither of them provided save_state().  IOW, so far it works kind of mutual
> exclusively v.s. save_state(), afaict.

Sorry for the lack of background information.

We follow the vfio SaveVMHandlers and add an extra vfio SaveVMHandlers
variant with is_active. In our internal codebase, we set it inactive
during migration but active in a specific scenario.

You are right that upstream tree works well. I sent this patch because I
assumed the semantics of is_active is similiar to the "needed" field in
vmsd.

I'd like to get your opinion on this. Perhaps this case we used won't
occur in upstream?

Thanks,
Yanfei






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration: check is_active for old-style vmstate
  2026-03-12  5:25 Yanfei Xu
@ 2026-03-12 15:36 ` Peter Xu
  2026-03-12 15:51   ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Xu @ 2026-03-12 15:36 UTC (permalink / raw)
  To: Yanfei Xu; +Cc: qemu-devel, farosas, caixiangfeng, liwenbo.liwenbo, yanfei.xu

On Thu, Mar 12, 2026 at 01:25:04PM +0800, Yanfei Xu wrote:
> > On Wed, Mar 11, 2026 at 01:16:58PM +0800, Yanfei Xu wrote:
> > > /old-style vmstate doesn't use vmsd and instead rely on SaveStateEntry/
> > > /ops. Check is_active for old-style vmstate to determine whether they/
> > > /should be skipped during migration./
> > 
> > Would you please dscribe the use case?
> > 
> > We only have two users in upstream tree that provided is_active(), and
> > neither of them provided save_state().  IOW, so far it works kind of mutual
> > exclusively v.s. save_state(), afaict.
> 
> Sorry for the lack of background information.
> 
> We follow the vfio SaveVMHandlers and add an extra vfio SaveVMHandlers
> variant with is_active. In our internal codebase, we set it inactive
> during migration but active in a specific scenario.
> 
> You are right that upstream tree works well. I sent this patch because I
> assumed the semantics of is_active is similiar to the "needed" field in
> vmsd.
> 
> I'd like to get your opinion on this. Perhaps this case we used won't
> occur in upstream?

Thanks for explaining.  That makes sense on its own, but I think you're
also correct since it won't occur in upstream then it means we're adding
dead code into upstream code that has zero use.

I suggest you stick your patch with your downstream, until you plan to
upstream the whole thing.

-- 
Peter Xu



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] migration: check is_active for old-style vmstate
  2026-03-12 15:36 ` Peter Xu
@ 2026-03-12 15:51   ` Peter Maydell
  0 siblings, 0 replies; 5+ messages in thread
From: Peter Maydell @ 2026-03-12 15:51 UTC (permalink / raw)
  To: Peter Xu
  Cc: Yanfei Xu, qemu-devel, farosas, caixiangfeng, liwenbo.liwenbo,
	yanfei.xu

On Thu, 12 Mar 2026 at 15:37, Peter Xu <peterx@redhat.com> wrote:
>
> On Thu, Mar 12, 2026 at 01:25:04PM +0800, Yanfei Xu wrote:
> > Sorry for the lack of background information.
> >
> > We follow the vfio SaveVMHandlers and add an extra vfio SaveVMHandlers
> > variant with is_active. In our internal codebase, we set it inactive
> > during migration but active in a specific scenario.
> >
> > You are right that upstream tree works well. I sent this patch because I
> > assumed the semantics of is_active is similiar to the "needed" field in
> > vmsd.
> >
> > I'd like to get your opinion on this. Perhaps this case we used won't
> > occur in upstream?
>
> Thanks for explaining.  That makes sense on its own, but I think you're
> also correct since it won't occur in upstream then it means we're adding
> dead code into upstream code that has zero use.

Incidentally we're now down to very few users left of the legacy
SaveVMHandlers mechanism: less than half a dozen, I think.
(I imagine the main pain point for getting rid of the rest is
retaining migration compat.)

-- PMM


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-03-12 15:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11  5:16 [PATCH] migration: check is_active for old-style vmstate Yanfei Xu
2026-03-11 17:34 ` Peter Xu
  -- strict thread matches above, loose matches on Subject: below --
2026-03-12  5:25 Yanfei Xu
2026-03-12 15:36 ` Peter Xu
2026-03-12 15:51   ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox