From: Sean Christopherson <seanjc@google.com>
To: "David Hildenbrand (Arm)" <david@kernel.org>
Cc: Pankaj Gupta <pankaj.gupta@amd.com>,
pbonzini@redhat.com, tglx@kernel.org, mingo@redhat.com,
dave.hansen@linux.intel.com, bp@alien8.de, x86@kernel.org,
thomas.lendacky@amd.com, hpa@zytor.com, yangge1116@126.com,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
stable@vger.kernel.org
Subject: Re: [PATCH] KVM: SEV: drop FOLL_LONGTERM for encrypted region registration
Date: Wed, 1 Jul 2026 09:30:20 -0700 [thread overview]
Message-ID: <akVAnGuiuJttE5-6@google.com> (raw)
In-Reply-To: <1cc159b9-5f94-4524-8e03-efe91601ccfc@kernel.org>
On Wed, Jul 01, 2026, David Hildenbrand (Arm) wrote:
> On 7/1/26 16:45, Pankaj Gupta wrote:
> > commit 7e066cb9b71a ("KVM: SEV: Use long-term pin when registering encrypted memory regions")
> > added FOLL_LONGTERM to sev_mem_enc_register_region() so anonymous guest RAM is
> > migrated out of MIGRATE_CMA/ZONE_MOVABLE before a long term pin. This breaks
> > virtio-pmem which has file backed (MAP_SHARED) host mapping where GUP rejects
> > FOLL_WRITE | FOLL_LONGTERM since:
> >
> > commit 8ac268436e6d ("mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings")
> > commit a6e79df92e4a ("mm/gup: disallow FOLL_LONGTERM GUP-fast writing to file-backed mappings").
> >
> > Drop FOLL_LONGTERM when registering encrypted memory regions and restore
> > the previous behavior.
>
> But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
Ya.
> If it is a longterm pin, it must use FOLL_LONGTERM. :/
Heh, well, KVM showed that that's not entirely true for many years :-)
Assuming we can't solve this some other way, and that there are "real" use cases
that were broken by adding FOLL_LONGTERM, maybe this as a hack-a-fix?
diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c
index 74fb15551e83..ea136d79c963 100644
--- a/arch/x86/kvm/svm/sev.c
+++ b/arch/x86/kvm/svm/sev.c
@@ -2752,6 +2752,25 @@ int sev_mem_enc_register_region(struct kvm *kvm,
region->pages = sev_pin_memory(kvm, range->addr, range->size, ®ion->npages,
FOLL_WRITE | FOLL_LONGTERM);
+
+ /*
+ * On failure, attempt a "short"-term pin for backwards compatibility,
+ * in quotes because this isn't actually a short-term pin. The kernel
+ * disallows long-term writable pins on file-backed memory as a partial
+ * defense against the fundamental problem that most filesystems don't
+ * play nice with kernel writes via GUP (true short-term pins are much
+ * less likely to be problematic).
+ *
+ * Unfortunately, KVM (incorrectly) used a short-term pin for years,
+ * and so can't *require* a long-term pin. And for this use case, the
+ * potential filesystem crashes that occur with kernel writes are a
+ * non-issue, as KVM isn't using this pin to access guest memory, the
+ * pin is performed purely to prevent the memory from being migrated.
+ */
+ if (IS_ERR(region->pages))
+ region->pages = sev_pin_memory(kvm, range->addr, range->size,
+ ®ion->npages, FOLL_WRITE);
+
if (IS_ERR(region->pages)) {
ret = PTR_ERR(region->pages);
goto e_free;
> I assume we fail in check_vma_flags()
>
> if ((gup_flags & FOLL_LONGTERM) && vma_is_fsdax(vma))
> return -EOPNOTSUPP;
>
> IIRC, fsdax cannot tolerate unbounded pins. Is that the case we are running into?
>
> How does vfio deal with that? (does it?)
>
> --
> Cheers,
>
> David
next prev parent reply other threads:[~2026-07-01 16:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-01 14:45 [PATCH] KVM: SEV: drop FOLL_LONGTERM for encrypted region registration Pankaj Gupta
2026-07-01 14:58 ` sashiko-bot
2026-07-01 16:25 ` David Hildenbrand (Arm)
2026-07-01 16:30 ` Sean Christopherson [this message]
2026-07-01 16:39 ` David Hildenbrand (Arm)
2026-07-01 16:56 ` Sean Christopherson
2026-07-06 12:03 ` Gupta, Pankaj
2026-07-07 10:04 ` David Hildenbrand (Arm)
2026-07-07 13:45 ` Gupta, Pankaj
2026-07-07 13:59 ` Sean Christopherson
2026-07-07 14:58 ` David Hildenbrand (Arm)
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=akVAnGuiuJttE5-6@google.com \
--to=seanjc@google.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=david@kernel.org \
--cc=hpa@zytor.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=pankaj.gupta@amd.com \
--cc=pbonzini@redhat.com \
--cc=stable@vger.kernel.org \
--cc=tglx@kernel.org \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
--cc=yangge1116@126.com \
/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.