From: Sean Christopherson <seanjc@google.com>
To: sashiko-reviews@lists.linux.dev
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: SEV: Do cache maintenance on the source VM during intra-host migration
Date: Wed, 23 Sep 2026 10:16:11 -0700 [thread overview]
Message-ID: <arQJW6bs7RRjLJFv@google.com> (raw)
In-Reply-To: <20260923165304.1662E1F000FF@smtp.kernel.org>
On Wed, Sep 23, 2026, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> - [Critical] kvm: sev: TOCTOU race in sev_migrate_from causes host memory corruption
> --
>
> commit b97586a7411bd5d8a55967b35859f6e485f10868
> Author: Sean Christopherson <seanjc@google.com>
>
> KVM: SEV: Do cache maintenance on the source VM during intra-host migration
>
> This commit manually performs cache maintenance on the source VM during
> intra-host migration. Since the source VM is converted to a non-SEV VM,
> automatic memory reclaim flows will not trigger the required cache
> maintenance, potentially leaving stale data in the CPU caches.
>
> > diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
> > index c9242c936a401..71923cb72d1d1 100644
> > --- a/arch/x86/kvm/svm/sev.c
> > +++ b/arch/x86/kvm/svm/sev.c
> > @@ -2048,6 +2048,12 @@ static void sev_migrate_from(struct kvm *dst_kvm, struct kvm *src_kvm)
> > src->pages_locked = 0;
> > src->es_active = false;
> >
> > + /*
> > + * Do cache maintenance on the source VM as it is no longer an SEV VM,
> > + * i.e. memory reclaim flows won't trigger cache maintenance on the VM.
> > + */
> > + sev_writeback_caches(src_kvm);
>
> [Severity: Critical]
> Is there a race condition here if memory is reclaimed concurrently?
>
> If a userspace process or kernel reclaim triggers a memory unmap (for
> example, via MADV_DONTNEED) concurrently with the KVM ioctl, it could happen
> in the window between setting src->active to false and calling
> sev_writeback_caches():
>
> CPU1 in sev_migrate_from():
> src->active = false;
>
> CPU2 running concurrent unmap:
> Since active is false, the automatic cache flush in
> sev_guest_memory_reclaimed is skipped.
> The host frees and reallocates the page.
>
> CPU1 in sev_migrate_from():
> sev_writeback_caches(src_kvm);
> Executes a hardware cache flush (wbnoinvd), which writes the guest's old
> dirty ciphertext over the new page owner's data.
>
> Because sev_migrate_from runs without mmap_lock or mmu_lock, MMU notifiers
> can run concurrently. Can this cause host memory corruption by overwriting
> newly allocated host pages with stale ciphertext?
Oof, yeah. It's a tiny window, but also trivial to fix and document.
next prev parent reply other threads:[~2026-09-23 17:16 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-23 16:37 [PATCH 0/2] KVM: SEV: Fix intra-host migration cache bugs Sean Christopherson
2026-09-23 16:37 ` [PATCH 1/2] KVM: SEV: Free have_run_cpus during VM destruction even if VM is no longer SEV Sean Christopherson
2026-09-23 16:53 ` sashiko-bot
2026-09-23 17:27 ` Sean Christopherson
2026-09-23 16:37 ` [PATCH 2/2] KVM: SEV: Do cache maintenance on the source VM during intra-host migration Sean Christopherson
2026-09-23 16:53 ` sashiko-bot
2026-09-23 17:16 ` Sean Christopherson [this message]
2026-09-26 4:37 ` [PATCH 0/2] KVM: SEV: Fix intra-host migration cache bugs Paolo Bonzini
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=arQJW6bs7RRjLJFv@google.com \
--to=seanjc@google.com \
--cc=kvm@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox