KVM: SEV: drop FOLL_LONGTERM for encrypted region registration
Subsystems (7)
PATCH 1/1 KVM: SEV: drop FOLL_LONGTERM for encrypted region registration
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.
--- arch/x86/kvm/svm/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/svm/sev.c +1 -1
@@ -2764,7 +2764,7 @@ int sev_mem_enc_register_region(struct kvm *kvm,return -ENOMEM ; region->pages =sev_pin_memory (kvm, range->addr, range->size, ®ion->npages, -FOLL_WRITE |FOLL_LONGTERM ); +FOLL_WRITE );if (IS_ERR (region->pages)) { ret =PTR_ERR (region->pages); goto e_free;
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [High] Dropping FOLL_LONGTERM creates a silent long-term pin, bypassing GUP safety checks for file-backed mappings and breaking CMA isolation for anonymous RAM.
Pre-existing issues:
- [Critical] Data race and unprotected state modification on mirror->enc_context_owner during SEV VM migration leads to list corruption and Use-After-Free. --
commit a611d4c7ad0ddfba6a16536a997563da04d1672f
Author: Pankaj Gupta <[email protected]>
KVM: SEV: drop FOLL_LONGTERM for encrypted region registration
This commit removes the FOLL_LONGTERM flag from sev_pin_memory() when registering encrypted memory regions. This aims to restore virtio-pmem compatibility by allowing GUP to succeed on file-backed host mappings.
Quoted 4 lines
arch/x86/kvm/svm/sev.c +0
-0
[ ... ]
arch/x86/kvm/svm/sev.c int sev_mem_enc_register_region(struct kvm *kvm, · line 2754
Quoted 6 lines
arch/x86/kvm/svm/sev.c +1
-1@@ -2751,7 +2751,7 @@ int sev_mem_enc_register_region(struct kvm *kvm,return -ENOMEM ; region->pages =sev_pin_memory (kvm, range->addr, range->size, ®ion->npages, -FOLL_WRITE |FOLL_LONGTERM ); +FOLL_WRITE );
[Severity: High]
Does removing FOLL_LONGTERM here create a silent long-term pin?
By dropping FOLL_LONGTERM, it appears we bypass GUP safety checks for file-backed mappings and break CMA isolation for anonymous RAM. This could allow guest VMs to permanently pin movable pages, leading to CMA allocation failures and breaking memory hot-unplug.
For file-backed mappings, could this cause filesystem operations like truncate() to loop indefinitely waiting for page refcounts to drop?
[Severity: Critical]
This is a pre-existing issue, but is there a data race on mirror->enc_context_owner during SEV VM migration?
Looking at sev_migrate_from(), it updates mirror->enc_context_owner without synchronization with concurrent readers. If a mirror VM is destroyed via sev_vm_destroy() concurrently with its owner being migrated, it can read the old owner_kvm pointer locklessly:
arch/x86/kvm/svm/sev.c:sev_vm_destroy() {
...
struct kvm *owner_kvm = sev->enc_context_owner; mutex_lock(&owner_kvm->lock); list_del(&sev->mirror_entry); mutex_unlock(&owner_kvm->lock); kvm_put_kvm(owner_kvm);
...
}
Could this block on the old source KVM lock while the migration thread moves the mirror to the new destination KVM list?
When the migration thread releases the lock, sev_vm_destroy() would wake up, attempt to delete the mirror from the list (corrupting the destination KVM list), and incorrectly drop a second reference to the source KVM, causing a use-after-free regression.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
David Hildenbrand (Arm)
maintainerQuoted 11 lines · Pankaj Gupta
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions") addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.
But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
If it is a longterm pin, it must use FOLL_LONGTERM. :/
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?)
Signature · 3 lines
Cheers, David
Sean Christopherson
maintainerQuoted 7 lines · David Hildenbrand (Arm)
Quoted 6 lines · Pankaj Gupta
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions") addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:
Quoted 7 lines
Quoted 5 lines
commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
Ya.
Quoted 1 line
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?
arch/x86/kvm/svm/sev.c +19 -0
@@ -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;
Quoted 13 lines
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?)
Signature · 3 lines
Cheers, David
David Hildenbrand (Arm)
maintainerQuoted 14 lines · Sean Christopherson
Quoted 13 lines · David Hildenbrand (Arm)
Quoted 11 lines · Pankaj Gupta
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions") addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.
Quoted 7 lines
Quoted 1 line
But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
Ya.
Quoted 1 line
If it is a longterm pin, it must use
FOLL_LONGTERM. :/Heh, well, KVM showed that that's not entirely true for many years :-)
What exactly do you mean? KVM MMUs sync through memory notifiers and doesn't need this.
It's only our "interesting" CoCo code :)
Quoted 3 lines
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?
Well, it's not a driver's decision to make. :P
But, can we actually whitelist virtio-pmem in GUP code somehow?
I mean, it does not suffer from the documented writeback issue, that we wanted to protect from. We similarly allow shmem and hugetlb there.
Signature · 3 lines
Cheers, David
Sean Christopherson
maintainerQuoted 19 lines · David Hildenbrand (Arm)
Quoted 18 lines · Sean Christopherson
Quoted 7 lines · David Hildenbrand (Arm)
Quoted 6 lines · Pankaj Gupta
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions") addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:Quoted 7 lines
Quoted 5 lines
commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
Ya.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
If it is a longterm pin, it must use
FOLL_LONGTERM. :/Heh, well, KVM showed that that's not entirely true for many years :-)
What exactly do you mean? KVM MMUs sync through memory notifiers and doesn't need this.
It's only our "interesting" CoCo code :)
Yeah, I'm just being cheeky and saying that it's obviously possible to do what is effectively a long-term pint without specifying FOLL_LONGTERM, i.e. saying it "must" use FOLL_LONGTERM isn't super duper strictly true.
Hi David,
Quoted 11 lines
Quoted 11 lines
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions") addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.
Quoted 8 lines
But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
If it is a longterm pin, it must use
FOLL_LONGTERM. :/I assume we fail in
check_vma_flags()if ((gup_flags & FOLL_LONGTERM) && vma_is_fsdax(vma)) return -EOPNOTSUPP;
Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax() returns false:
Quoted 2 lines
IIRC, fsdax cannot tolerate unbounded pins. Is that the case we are running into?
Host side backend is regular file backed memory (no fsdax).
Thanks,
Pankaj
Quoted 3 lines
How does vfio deal with that? (does it?)
David Hildenbrand (Arm)
maintainerQuoted 22 lines · Pankaj
Hi David,
Quoted 20 lines
Quoted 7 lines
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions")
addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:Quoted 7 lines
commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings")
commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
If it is a longterm pin, it must use
FOLL_LONGTERM. :/I assume we fail in
check_vma_flags()
Quoted 7 lines
Quoted 2 lines
if ((
gup_flags&FOLL_LONGTERM) &&vma_is_fsdax(vma)) return-EOPNOTSUPP;Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax()returns false:
Ah, okay, so fsdax is not involved and we really only fail because of the writable_file_mapping_allowed() check.
I was for a second thinking in terms of nested virt :)
Quoted 5 lines
Quoted 3 lines
IIRC, fsdax cannot tolerate unbounded pins. Is that the case we are running into?
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.
A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"
Hmmm
Signature · 3 lines
Cheers, David
Quoted 54 lines
Quoted 21 lines
Hi David,
Quoted 18 lines
Quoted 7 lines
commit
7e066cb9b71a("KVM: SEV: Use long-term pin when registering encrypted memory regions")
addedFOLL_LONGTERMtosev_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 rejectsFOLL_WRITE|FOLL_LONGTERMsince:Quoted 7 lines
commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings")
commita6e79df92e4a("mm/gup: disallowFOLL_LONGTERMGUP-fast writing to file-backed mappings").Drop
FOLL_LONGTERMwhen registering encrypted memory regions and restore the previous behavior.But that breaks the original issue of breaking ZONE_MOVABLE/CMA?
If it is a longterm pin, it must use
FOLL_LONGTERM. :/Quoted 8 lines
Quoted 4 lines
I assume we fail in
check_vma_flags()if ((
gup_flags&FOLL_LONGTERM) &&vma_is_fsdax(vma)) return-EOPNOTSUPP;Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax()returns false:Ah, okay, so fsdax is not involved and we really only fail because of the
writable_file_mapping_allowed()check.I was for a second thinking in terms of nested virt :)
Quoted 2 lines
Quoted 1 line
IIRC, fsdax cannot tolerate unbounded pins. Is that the case we are running into?
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
Quoted 6 lines
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"Hmmm
Yes. For file based mapping we don't allow long term pinning.
If we take into account the fragmentation concerns for MIGRATE_CMA and ZONE_MOVABLE allocations
solvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on FOLL_WRITE when FOLL_LONGTERM fails as suggested by Sean.
2. Explicitly restrict long-term pinning for file-backed mappings with a change like the patch below [1].
David, Sean,
Do you have a preference between these two approaches? I am leaning toward towards option 2.
Thank you!
Pankaj
---
[1]
arch/x86/kvm/svm/sev.c | 27 +++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)
arch/x86/kvm/svm/sev.c +0 -0
@@ -2743,6 +2743,29 @@ int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp)
return r;
}
+static unsigned int sev_region_gup_flags(unsigned long uaddr, unsigned long ulen) +{
+ struct mm_struct *mm = current->mm;
+ unsigned long end = uaddr + ulen;
+ struct vm_area_struct *vma;
+ unsigned int flags = FOLL_WRITE | FOLL_LONGTERM;
+ VMA_ITERATOR(vmi, mm, uaddr);
+
+ if (ulen == 0 || end < uaddr)
+ return FOLL_WRITE;
+
+ mmap_read_lock(mm);
+ for_each_vma_range(vmi, vma, end) {
+ if (!vma_is_anonymous(vma)) {
+ flags = FOLL_WRITE;
+ break;
+ }
+ }
+ mmap_read_unlock(mm);
+
+ return flags;
+}
+
int sev_mem_enc_register_region(struct kvm *kvm,
struct kvm_enc_region *range)
{
@@ -2764,7 +2787,7 @@ int sev_mem_enc_register_region(struct kvm *kvm, return -ENOMEM;
region->pages = sev_pin_memory(kvm, range->addr, range->size, ®ion->npages, - FOLL_WRITE | FOLL_LONGTERM);
+ sev_region_gup_flags(range->addr, range->size));
if (IS_ERR(region->pages)) {
ret = PTR_ERR(region->pages);
goto e_free;
(END)
Sean Christopherson
maintainerQuoted 7 lines · Pankaj Gupta
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
IIRC, fsdax cannot tolerate unbounded pins. Is that the case we are running into?
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
The problem that _is_ "isolated" to SEV though, is that this used to work :-/
Quoted 29 lines
Quoted 12 lines
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
Quoted 6 lines
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"Hmmm
Yes. For file based mapping we don't allow long term pinning.
If we take into account the fragmentation concerns for
MIGRATE_CMAandZONE_MOVABLEallocationssolvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on
FOLL_WRITEwhenFOLL_LONGTERMfails as suggested by Sean.
Quoted 7 lines
2. Explicitly restrict long-term pinning for file-backed mappings with a change like the patch below [1].
David, Sean,
Do you have a preference between these two approaches? I am leaning toward towards option 2.
Option 1. Option 2 has a TOCTOU bug (the VMA could be changed after dropping mmap_lock), and I'd rather not bleed any more mm/ details into KVM than is
required: falling back to a non-FOLL_LONGTERM acknowledges that there are mapping types that don't support WRITE+LONGTERM, but checking vma_is_anonymous() takes things a few steps further by forcing KVM to know what types of mappings are problematic.
Quoted 52 lines
arch/x86/kvm/svm/sev.c +23
-0@@ -2743,6 +2743,29 @@ int sev_mem_enc_ioctl(struct kvm *kvm, void __user *argp) return r; } +static unsigned int sev_region_gup_flags (unsigned long uaddr,unsigned long ulen) +{ + struct mm_struct *mm = current->mm; + unsigned long end = uaddr + ulen; + struct vm_area_struct *vma; + unsigned int flags = FOLL_WRITE | FOLL_LONGTERM; + VMA_ITERATOR(vmi, mm, uaddr); + + if (ulen == 0 || end < uaddr) + return FOLL_WRITE; + + mmap_read_lock(mm); + for_each_vma_range(vmi, vma, end) { + if (!vma_is_anonymous(vma)) { + flags = FOLL_WRITE; + break; + } + } + mmap_read_unlock(mm); + + return flags; +} + int sev_mem_enc_register_region(struct kvm *kvm,struct
kvm_enc_region*range) {arch/x86/kvm/svm/sev.c +1
-1@@ -2764,7 +2787,7 @@ int sev_mem_enc_register_region(struct kvm *kvm, return -ENOMEM; region->pages = sev_pin_memory(kvm, range->addr, range->size, ®ion->npages, - FOLL_WRITE | FOLL_LONGTERM); +sev_region_gup_flags (range->addr, range->size)); if (IS_ERR(region->pages)) { ret = PTR_ERR(region->pages);goto
e_free;
(END)
David Hildenbrand (Arm)
maintainerQuoted 40 lines · Pankaj
Quoted 31 lines
Quoted 7 lines
Hi David,
Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax()returns false:Ah, okay, so fsdax is not involved and we really only fail because of the
writable_file_mapping_allowed()check.I was for a second thinking in terms of nested virt :)
Quoted 1 line
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
Quoted 6 lines
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"Hmmm
Yes. For file based mapping we don't allow long term pinning.
Quoted 7 lines
If we take into account the fragmentation concerns for
MIGRATE_CMAandZONE_MOVABLEallocationssolvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on
FOLL_WRITEwhenFOLL_LONGTERMfails as suggested by Sean.
That is just not acceptable, as it breaks random other stuff (MIGRATE_CMA, as one example) besides the file-pinning problems that Lorenzo added.
If we're going to hack something in, then that we bypass the file writeback check. Not that we don't use FOLL_LONGTERM.
I'd hate to use a GUP flag to indicate "this is a legacy hack", but it clearly isolates the issue (needs a better name obviously):
include/linux/mm_types.h +3 -0
@@ -1912,6 +1912,9 @@ enum {*/ FOLL_HONOR_NUMA_FAULT =1 <<12 , +/* TODO */ + FOLL_LONGTERM = 1 << 13, + /* See also internal only FOLL flags in mm/internal.h */ };
mm/gup.c +4 -4
@@ -1186,8 +1186,8 @@ static bool writable_file_mapping_allowed(struct vm_area_struct *vma,* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the case we disallow. */ -if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM )) != - (FOLL_PIN |FOLL_LONGTERM )) +if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK )) != + (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK ))return true;/*
@@ -2746,7 +2746,7 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags)* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the one we disallow. */ -if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) == +if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE |FOLL_LONGTERM_HACK )) == (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) reject_file_backed = true;
@@ -3180,7 +3180,7 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages,int locked =0 ;int ret; -if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM | +if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM |FOLL_LONGTERM_HACK |FOLL_FORCE |FOLL_PIN |FOLL_GET |FOLL_FAST_ONLY |FOLL_NOFAULT |FOLL_PCI_P2PDMA |FOLL_HONOR_NUMA_FAULT )))
Signature · 3 lines
Cheers, David
Hi David, Sean,
Thank you for the discussion!
Quoted 59 lines
Quoted 9 lines
Yes. For file based mapping we don't allow long term pinning.
If we take into account the fragmentation concerns for
MIGRATE_CMAandZONE_MOVABLEallocationssolvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on
FOLL_WRITEwhenFOLL_LONGTERMfails as suggested by Sean.That is just not acceptable, as it breaks random other stuff (
MIGRATE_CMA, as one example) besides the file-pinning problems that Lorenzo added.If we're going to hack something in, then that we bypass the file writeback check. Not that we don't use
FOLL_LONGTERM.I'd hate to use a GUP flag to indicate "this is a legacy hack", but it clearly isolates the issue (needs a better name obviously):
include/linux/mm_types.h +3
-0@@ -1912,6 +1912,9 @@ enum {*/ FOLL_HONOR_NUMA_FAULT =1 <<12 , +/* TODO */ + FOLL_LONGTERM = 1 << 13, + /* See also internal only FOLL flags in mm/internal.h */ };mm/gup.c +3
-3@@ -1186,8 +1186,8 @@ static bool writable_file_mapping_allowed(struct vm_area_struct *vma,* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the case we disallow. */ -if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM )) != - (FOLL_PIN |FOLL_LONGTERM )) +if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK )) != + (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK ))return true;/* @@ -2746,7 +2746,7 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags)* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the one we disallow. */ -if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) == +if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE |FOLL_LONGTERM_HACK )) == (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) reject_file_backed = true;
mm/gup.c static int gup_fast_fallback(unsigned long start, unsigned long nr_pages, · line 3186
Quoted 8 lines
mm/gup.c +1
-1@@ -3180,7 +3180,7 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages,int locked =0 ;int ret; -if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM | +if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM |FOLL_LONGTERM_HACK |FOLL_FORCE |FOLL_PIN |FOLL_GET |FOLL_FAST_ONLY |FOLL_NOFAULT |FOLL_PCI_P2PDMA |FOLL_HONOR_NUMA_FAULT )))
David,
Yes, the above approach works with few changes [2]. If it looks okay will send a v2 .
Best regards,
Pankaj
[2]
Quoted 99 lines
include/linux/mm_types.h +3
-0@@ -1911,6 +1911,14 @@ enum {*/ FOLL_HONOR_NUMA_FAULT = 1 << 12, + /* +* Long-term pin without kernel GUP writes. For callers that pin +* writable file-backed mappings only to prevent migration. Must be
+ * used withFOLL_PINand FOLL_LONGTERM. Bypasses the writable + * file-backed long-term pin restriction ingup.c.
+ */
+ FOLL_PIN_NO_GUP_WRITE = 1 << 13,
+
/* See also internal only FOLL flags inmm/internal.h*/ };mm/gup.c +1
-0@@ -1186,6 +1186,10 @@ static boolwritable_file_mapping_allowed(struct vm_area_struct *vma, * If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the case we disallow. */ + if ((gup_flags & (FOLL_PIN | FOLL_LONGTERM |
FOLL_PIN_NO_GUP_WRITE)) ==
+ (FOLL_PIN |FOLL_LONGTERM|FOLL_PIN_NO_GUP_WRITE)) + return true;
+
if ((gup_flags& (FOLL_PIN|FOLL_LONGTERM)) != (FOLL_PIN|FOLL_LONGTERM))
return true;mm/gup.c +5
-0@@ -2530,6 +2534,11 @@ static bool is_valid_gup_args(struct page **pages, int *locked, if (WARN_ON_ONCE(!(gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))) return false; + if (WARN_ON_ONCE((gup_flags & FOLL_PIN_NO_GUP_WRITE) && + (gup_flags & (FOLL_PIN | FOLL_LONGTERM)) != + (FOLL_PIN | FOLL_LONGTERM))) + return false; + /* Pages input must be given if using GET/PIN */ if (WARN_ON_ONCE((gup_flags & (FOLL_GET | FOLL_PIN)) && !pages))return false;
mm/gup.c +1
-0@@ -2747,7 +2756,8 @@ static bool gup_fast_folio_allowed(struct folio*folio, unsigned int flags) * pin is the most egregious case so this is the one we disallow. */ + if ((gup_flags & (FOLL_PIN | FOLL_LONGTERM |
FOLL_PIN_NO_GUP_WRITE)) ==
+ (FOLL_PIN |FOLL_LONGTERM|FOLL_PIN_NO_GUP_WRITE)) + return true;
+
if ((gup_flags& (FOLL_PIN|FOLL_LONGTERM)) != (FOLL_PIN|FOLL_LONGTERM))
return true;mm/gup.c +5
-0@@ -2530,6 +2534,11 @@ static bool is_valid_gup_args(struct page **pages, int *locked, if (WARN_ON_ONCE(!(gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))) return false; + if (WARN_ON_ONCE((gup_flags & FOLL_PIN_NO_GUP_WRITE) && + (gup_flags & (FOLL_PIN | FOLL_LONGTERM)) != + (FOLL_PIN | FOLL_LONGTERM))) + return false; + /* Pages input must be given if using GET/PIN */ if (WARN_ON_ONCE((gup_flags & (FOLL_GET | FOLL_PIN)) && !pages))return false;
mm/gup.c +0
-0@@ -2747,7 +2756,8 @@ static bool gup_fast_folio_allowed(struct folio*folio, unsigned int flags) * pin is the most egregious case so this is the one we disallow. */ if ((flags & (
FOLL_PIN|FOLL_LONGTERM|FOLL_WRITE)) ==- (FOLL_PIN | FOLL_LONGTERM | FOLL_WRITE)) + (FOLL_PIN | FOLL_LONGTERM | FOLL_WRITE) &&+ !(flags &
FOLL_PIN_NO_GUP_WRITE))
reject_file_backed= true;/* We hold a folio reference, so we can safely access folio fields. */
mm/gup.c +1
-1@@ -3180,7 +3190,7 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages, int locked = 0; int ret; - if (WARN_ON_ONCE(gup_flags & ~(FOLL_WRITE | FOLL_LONGTERM | + if (WARN_ON_ONCE(gup_flags & ~(FOLL_WRITE | FOLL_LONGTERM |
FOLL_PIN_NO_GUP_WRITE|
FOLL_FORCE |FOLL_PIN|FOLL_GET|FOLL_FAST_ONLY|FOLL_NOFAULT|FOLL_PCI_P2PDMA|FOLL_HONOR_NUMA_FAULT)))
Lorenzo Stoakes
reviewerQuoted 49 lines · David Hildenbrand (Arm)
Quoted 40 lines · Pankaj
Quoted 31 lines
Quoted 7 lines
Hi David,
Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax()returns false:Ah, okay, so fsdax is not involved and we really only fail because of the
writable_file_mapping_allowed()check.I was for a second thinking in terms of nested virt :)
Quoted 1 line
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
Quoted 6 lines
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"Hmmm
Yes. For file based mapping we don't allow long term pinning.
Quoted 7 lines
If we take into account the fragmentation concerns for
MIGRATE_CMAandZONE_MOVABLEallocationssolvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on
FOLL_WRITEwhenFOLL_LONGTERMfails as suggested by Sean.
Quoted 8 lines
That is just not acceptable, as it breaks random other stuff (
MIGRATE_CMA, as one example) besides the file-pinning problems that Lorenzo added.If we're going to hack something in, then that we bypass the file writeback check. Not that we don't use
FOLL_LONGTERM.I'd hate to use a GUP flag to indicate "this is a legacy hack", but it clearly isolates the issue (needs a better name obviously):
So under what circumstances are we happy with totally breaking dirty tracking? :/ seems iffy, and exposing this to drivers generally is a bit worrysome.
Quoted 21 lines
include/linux/mm_types.h +3
-0@@ -1912,6 +1912,9 @@ enum {*/ FOLL_HONOR_NUMA_FAULT =1 <<12 , +/* TODO */ + FOLL_LONGTERM = 1 << 13, + /* See also internal only FOLL flags in mm/internal.h */ };mm/gup.c +0
-0
mm/gup.c static bool writable_file_mapping_allowed(struct vm_area_struct *vma, · line 1191
Quoted 8 lines
mm/gup.c +2
-2@@ -1186,8 +1186,8 @@ static bool writable_file_mapping_allowed(struct vm_area_struct *vma,* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the case we disallow. */ -if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM )) != - (FOLL_PIN |FOLL_LONGTERM )) +if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK )) != + (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK ))return true;
Hmm I'm confused, you're then allowing FOLL_PIN | FOLL_LONGTERM, but disallowing FOLL_PIN | FOLL_LONGTERM | FOLL_LONGTERM_HACK?
By the way I think this should be expressed better if I criticise myself here :)
So like:
if ((gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))
Or even:
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return false; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return false;
But I'm confused as to why we are suddenly allowing something broken and what this hack flag is supposed to achieve?
Shouldn't this rather be:
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return true; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return true; /* ...and not overridden... */ if (gup_flags & FOLL_LONGTERM_HACK) return true; /* ...and dirty tracking is required. */ return !vma_needs_dirty_tracking(vma); }
mm/gup.c static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) · line 2750
Quoted 9 lines
mm/gup.c +1
-1/* @@ -2746,7 +2746,7 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags)* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the one we disallow. */ -if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) == +if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE |FOLL_LONGTERM_HACK )) == (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE ))
Yeah this is just a bit horrid having to stare at a this a while... So FOLL_LONGTERM_HACK would enable here.
Be nice to avoid this form of it as it's difficult to understand, do something like above or a clearer version anyway (probably best abstracted to a small function).
Quoted 16 lines
mm/gup.c +1
-2reject_file_backed = true;@@ -3180,7 +3180,7 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages,int locked =0 ;int ret; -if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM | +if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM |FOLL_LONGTERM_HACK |FOLL_FORCE |FOLL_PIN |FOLL_GET |FOLL_FAST_ONLY |FOLL_NOFAULT |FOLL_PCI_P2PDMA |FOLL_HONOR_NUMA_FAULT ))) --Cheers,
Quoted 1 line
David
Thanks, Lorenzo
Hi Lorenzo,
Quoted 48 lines
Quoted 48 lines
Quoted 38 lines
Quoted 30 lines
Quoted 6 lines
Hi David,
Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax()returns false:Ah, okay, so fsdax is not involved and we really only fail because of the
writable_file_mapping_allowed()check.I was for a second thinking in terms of nested virt :)
Quoted 1 line
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
Quoted 6 lines
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"Hmmm
Yes. For file based mapping we don't allow long term pinning.
Quoted 7 lines
If we take into account the fragmentation concerns for
MIGRATE_CMAandZONE_MOVABLEallocationssolvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on
FOLL_WRITEwhenFOLL_LONGTERMfails as suggested by Sean.That is just not acceptable, as it breaks random other stuff (
MIGRATE_CMA, as one example) besides the file-pinning problems that Lorenzo added.
Quoted 7 lines
Quoted 5 lines
If we're going to hack something in, then that we bypass the file writeback check. Not that we don't use
FOLL_LONGTERM.I'd hate to use a GUP flag to indicate "this is a legacy hack", but it clearly isolates the issue (needs a better name obviously):
So under what circumstances are we happy with totally breaking dirty tracking? :/ seems iffy, and exposing this to drivers generally is a bit worrysome.
The intention is to allow long-term pinning of file-backed mappings only for migration avoidance,
without kernel GUP writes, and therefore not impacting dirty tracking.
Quoted 15 lines
Quoted 15 lines
include/linux/mm_types.h +3
-0@@ -1912,6 +1912,9 @@ enum {*/ FOLL_HONOR_NUMA_FAULT =1 <<12 , +/* TODO */ + FOLL_LONGTERM = 1 << 13, + /* See also internal only FOLL flags in mm/internal.h */ };
Quoted 15 lines
mm/gup.c static bool writable_file_mapping_allowed(struct vm_area_struct *vma, · line 1191
Quoted 13 lines
mm/gup.c +2
-2@@ -1186,8 +1186,8 @@ static bool writable_file_mapping_allowed(struct vm_area_struct *vma,* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the case we disallow. */ -if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM )) != - (FOLL_PIN |FOLL_LONGTERM )) +if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK )) != + (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK ))return true;Hmm I'm confused, you're then allowing
FOLL_PIN|FOLL_LONGTERM, but disallowingFOLL_PIN|FOLL_LONGTERM|FOLL_LONGTERM_HACK?
Yes, I addressed this in my reply, but it wasn't a clean inline response.
Quoted 21 lines
By the way I think this should be expressed better if I criticise myself here :)
So like:
if ((gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))Or even:
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return false; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return false;But I'm confused as to why we are suddenly allowing something broken and what this hack flag is supposed to achieve?
Shouldn't this rather be:
Quoted 12 lines
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return true; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return true; /* ...and not overridden... */ if (gup_flags & FOLL_LONGTERM_HACK) return true; /* ...and dirty tracking is required. */ return !vma_needs_dirty_tracking(vma); }
Yes, this looks much better. Will incorporate this.
Quoted 12 lines
mm/gup.c static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) · line 2750
Quoted 9 lines
mm/gup.c +1
-1/* @@ -2746,7 +2746,7 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags)* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the one we disallow. */ -if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) == +if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE |FOLL_LONGTERM_HACK )) == (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE ))Yeah this is just a bit horrid having to stare at a this a while... So
FOLL_LONGTERM_HACKwould enable here.
Quoted 3 lines
Be nice to avoid this form of it as it's difficult to understand, do something like above or a clearer version anyway (probably best abstracted to a small function).
Sure.
Also, I am also planning to rename (FOLL_LONGTERM_HACK -> FOLL_PIN_NO_GUP_WRITE) in v2.
Please let me know if you have a preference.
Thanks,
Pankaj
Quoted 19 lines
Quoted 17 lines
mm/gup.c +1
-2reject_file_backed = true;@@ -3180,7 +3180,7 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages,int locked =0 ;int ret; -if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM | +if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM |FOLL_LONGTERM_HACK |FOLL_FORCE |FOLL_PIN |FOLL_GET |FOLL_FAST_ONLY |FOLL_NOFAULT |FOLL_PCI_P2PDMA |FOLL_HONOR_NUMA_FAULT ))) --Cheers,
Quoted 1 line
David
Thanks, Lorenzo
Lorenzo Stoakes
reviewerQuoted 55 lines · Pankaj
Hi Lorenzo,
Quoted 53 lines
Quoted 53 lines
Quoted 38 lines
Quoted 30 lines
Quoted 6 lines
Hi David,
Yes, it fails in this path but for file backed mapping, vma_is_fsdax() returns false because
vma_is_dax()returns false:Ah, okay, so fsdax is not involved and we really only fail because of the
writable_file_mapping_allowed()check.I was for a second thinking in terms of nested virt :)
Quoted 1 line
Host side backend is regular file backed memory (no fsdax).
Okay, so we'll end up mapping an ordinary file into VM memory, and expose that to the VM as part of virtio-pmem device.
That also means that vfio etc. won't be able to longterm-pin such device memory. So this is not a problem isolated to SEV.
Forbidding to longterm pin is actually the right thing to do if the filesystem relies on writenotify, as spelled out by Lorenzo's commit:
"
Writing to file-backed mappings which require folio dirty tracking using GUP is a fundamentally broken operation, as kernel write access to GUP mappings do not adhere to the semantics expected by a file system.A GUP caller uses the direct mapping to access the folio, which does not cause write notify to trigger, nor does it enforce that the caller marks the folio dirty.
Quoted 6 lines
The problem arises when, after an initial write to the folio, writeback results in the folio being cleaned and then the caller, via the GUP interface, writes to the folio again.
"Hmmm
Yes. For file based mapping we don't allow long term pinning.
Quoted 7 lines
If we take into account the fragmentation concerns for
MIGRATE_CMAandZONE_MOVABLEallocationssolvable with FOLL_LONGTERM, I can think of two options(tested) to allow file based mappings as well:
1. Fallback on
FOLL_WRITEwhenFOLL_LONGTERMfails as suggested by Sean.That is just not acceptable, as it breaks random other stuff (
MIGRATE_CMA, as one example) besides the file-pinning problems that Lorenzo added.If we're going to hack something in, then that we bypass the file writeback check. Not that we don't use
FOLL_LONGTERM.I'd hate to use a GUP flag to indicate "this is a legacy hack", but it clearly isolates the issue (needs a better name obviously):
Quoted 7 lines
Quoted 2 lines
So under what circumstances are we happy with totally breaking dirty tracking? :/ seems iffy, and exposing this to drivers generally is a bit worrysome.
The intention is to allow long-term pinning of file-backed mappings only for migration avoidance,
without kernel GUP writes, and therefore not impacting dirty tracking.
OK as long as that's made clear in the patch, commit message, comments etc. :)
Quoted 32 lines
Quoted 16 lines
Quoted 16 lines
include/linux/mm_types.h +3
-0@@ -1912,6 +1912,9 @@ enum {*/ FOLL_HONOR_NUMA_FAULT =1 <<12 , +/* TODO */ + FOLL_LONGTERM = 1 << 13, + /* See also internal only FOLL flags in mm/internal.h */ };Quoted 15 lines
mm/gup.c static bool writable_file_mapping_allowed(struct vm_area_struct *vma, · line 1191
Quoted 13 lines
mm/gup.c +2
-2@@ -1186,8 +1186,8 @@ static bool writable_file_mapping_allowed(struct vm_area_struct *vma,* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the case we disallow. */ -if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM )) != - (FOLL_PIN |FOLL_LONGTERM )) +if ((gup_flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK )) != + (FOLL_PIN |FOLL_LONGTERM |FOLL_LONGTERM_HACK ))return true;Hmm I'm confused, you're then allowing
FOLL_PIN|FOLL_LONGTERM, but disallowingFOLL_PIN|FOLL_LONGTERM|FOLL_LONGTERM_HACK?
Quoted 1 line
Yes, I addressed this in my reply, but it wasn't a clean inline response.
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Quoted 35 lines
Quoted 22 lines
By the way I think this should be expressed better if I criticise myself here :)
So like:
if ((gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))Or even:
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return false; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return false;But I'm confused as to why we are suddenly allowing something broken and what this hack flag is supposed to achieve?
Shouldn't this rather be:
Quoted 12 lines
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return true; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return true; /* ...and not overridden... */ if (gup_flags & FOLL_LONGTERM_HACK) return true; /* ...and dirty tracking is required. */ return !vma_needs_dirty_tracking(vma); }
Quoted 1 line
Yes, this looks much better. Will incorporate this.
Thanks!
Quoted 13 lines
Quoted 13 lines
mm/gup.c static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags) · line 2750
Quoted 10 lines
mm/gup.c +1
-1/* @@ -2746,7 +2746,7 @@ static bool gup_fast_folio_allowed(struct folio *folio, unsigned int flags)* If we aren't pinning then no problematic write can occur. A long term * pin is the most egregious case so this is the one we disallow. */ -if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE )) == +if ((flags & (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE |FOLL_LONGTERM_HACK )) == (FOLL_PIN |FOLL_LONGTERM |FOLL_WRITE ))Yeah this is just a bit horrid having to stare at a this a while... So
FOLL_LONGTERM_HACKwould enable here.
Quoted 8 lines
Quoted 3 lines
Be nice to avoid this form of it as it's difficult to understand, do something like above or a clearer version anyway (probably best abstracted to a small function).
Sure.
Also, I am also planning to rename (
FOLL_LONGTERM_HACK->FOLL_PIN_NO_GUP_WRITE) in v2.
hmm but we have FOLL_LONGTERM as an adjunct to FOLL_PIN (doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).
Also don't we want to encode the legacy aspect here?
Maybe FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)
Quoted 26 lines
Please let me know if you have a preference.
Thanks,
Pankaj
Quoted 19 lines
Quoted 17 lines
mm/gup.c +1
-2reject_file_backed = true;@@ -3180,7 +3180,7 @@ static int gup_fast_fallback(unsigned long start, unsigned long nr_pages,int locked =0 ;int ret; -if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM | +if (WARN_ON_ONCE (gup_flags & ~(FOLL_WRITE |FOLL_LONGTERM |FOLL_LONGTERM_HACK |FOLL_FORCE |FOLL_PIN |FOLL_GET |FOLL_FAST_ONLY |FOLL_NOFAULT |FOLL_PCI_P2PDMA |FOLL_HONOR_NUMA_FAULT ))) --Cheers,
Quoted 1 line
David
Thanks, Lorenzo
Cheers, Lorenzo
David Hildenbrand (Arm)
maintainerQuoted 74 lines · Lorenzo Stoakes
Quoted 9 lines · Pankaj
Hi Lorenzo,
Quoted 2 lines
So under what circumstances are we happy with totally breaking dirty tracking? :/ seems iffy, and exposing this to drivers generally is a bit worrysome.
The intention is to allow long-term pinning of file-backed mappings only for migration avoidance,
without kernel GUP writes, and therefore not impacting dirty tracking.
OK as long as that's made clear in the patch, commit message, comments etc. :)
Quoted 5 lines
Quoted 3 lines
Hmm I'm confused, you're then allowing
FOLL_PIN|FOLL_LONGTERM, but disallowingFOLL_PIN|FOLL_LONGTERM|FOLL_LONGTERM_HACK?Yes, I addressed this in my reply, but it wasn't a clean inline response.
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Quoted 35 lines
Quoted 22 lines
By the way I think this should be expressed better if I criticise myself here :)
So like:
if ((gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))Or even:
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return false; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return false;But I'm confused as to why we are suddenly allowing something broken and what this hack flag is supposed to achieve?
Shouldn't this rather be:
Quoted 12 lines
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return true; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return true; /* ...and not overridden... */ if (gup_flags & FOLL_LONGTERM_HACK) return true; /* ...and dirty tracking is required. */ return !vma_needs_dirty_tracking(vma); }Quoted 1 line
Yes, this looks much better. Will incorporate this.
Thanks!
Quoted 5 lines
Quoted 5 lines
Yeah this is just a bit horrid having to stare at a this a while... So
FOLL_LONGTERM_HACKwould enable here.Quoted 8 lines
Quoted 3 lines
Be nice to avoid this form of it as it's difficult to understand, do something like above or a clearer version anyway (probably best abstracted to a small function).
Sure.
Also, I am also planning to rename (
FOLL_LONGTERM_HACK->FOLL_PIN_NO_GUP_WRITE) in v2.
Quoted 7 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)
I'm confused about the _READONLY, well. and the FOLL_PIN_NO_GUP_WRITE.
We want to longterm write-pin.
@Pankaj, how come you would call this "FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?
I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
Signature · 3 lines
Cheers, David
Lorenzo Stoakes
reviewerQuoted 85 lines · David Hildenbrand (Arm)
Quoted 74 lines · Lorenzo Stoakes
Quoted 9 lines · Pankaj
Hi Lorenzo,
Quoted 2 lines
So under what circumstances are we happy with totally breaking dirty tracking? :/ seems iffy, and exposing this to drivers generally is a bit worrysome.
The intention is to allow long-term pinning of file-backed mappings only for migration avoidance,
without kernel GUP writes, and therefore not impacting dirty tracking.
OK as long as that's made clear in the patch, commit message, comments etc. :)
Quoted 5 lines
Quoted 3 lines
Hmm I'm confused, you're then allowing
FOLL_PIN|FOLL_LONGTERM, but disallowingFOLL_PIN|FOLL_LONGTERM|FOLL_LONGTERM_HACK?Yes, I addressed this in my reply, but it wasn't a clean inline response.
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Quoted 35 lines
Quoted 22 lines
By the way I think this should be expressed better if I criticise myself here :)
So like:
if ((gup_flags & FOLL_PIN) && (gup_flags & FOLL_LONGTERM))Or even:
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return false; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return false;But I'm confused as to why we are suddenly allowing something broken and what this hack flag is supposed to achieve?
Shouldn't this rather be:
Quoted 12 lines
/* Only an issue if we pin... */ if (!(gup_flags & FOLL_PIN)) return true; /* ...and that pin is longterm... */ if (!(gup_flags & FOLL_LONGTERM)) return true; /* ...and not overridden... */ if (gup_flags & FOLL_LONGTERM_HACK) return true; /* ...and dirty tracking is required. */ return !vma_needs_dirty_tracking(vma); }Quoted 1 line
Yes, this looks much better. Will incorporate this.
Thanks!
Quoted 5 lines
Quoted 5 lines
Yeah this is just a bit horrid having to stare at a this a while... So
FOLL_LONGTERM_HACKwould enable here.Quoted 8 lines
Quoted 3 lines
Be nice to avoid this form of it as it's difficult to understand, do something like above or a clearer version anyway (probably best abstracted to a small function).
Sure.
Also, I am also planning to rename (
FOLL_LONGTERM_HACK->FOLL_PIN_NO_GUP_WRITE) in v2.Quoted 7 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)I'm confused about the
_READONLY, well. and theFOLL_PIN_NO_GUP_WRITE.
Quoted 7 lines
We want to longterm write-pin.
@Pankaj, how come you would call this "
FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
I based it on Gupta saying 'without kernel GUP writes, and therefore not impacting dirty tracking'
I mean I think we definitely need some clarification here yes :)
Not really got the bandwidth to dig deep into GUP again :P
Gupta could you please clarify exactly what's happening here?
Quoted 5 lines
--
Cheers,David
Thanks, Lorenzo
Quoted 6 lines
Quoted 6 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Quoted 7 lines
Quoted 1 line
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)I'm confused about the
_READONLY, well. and theFOLL_PIN_NO_GUP_WRITE.We want to longterm write-pin.
@Pankaj, how come you would call this "
FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?
Honestly, I did not finalize it then, just tossed the name for some suggestion :-)
Quoted 2 lines
I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
Maybe FOLL_LONGTERM_LEGACY_, still pondering what that name could be ...
Thanks,
Pankaj
David Hildenbrand (Arm)
maintainerQuoted 30 lines · Lorenzo Stoakes
Quoted 21 lines · David Hildenbrand (Arm)
Quoted 10 lines · Lorenzo Stoakes
OK as long as that's made clear in the patch, commit message, comments etc. :)
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Thanks!
Quoted 7 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)I'm confused about the
_READONLY, well. and theFOLL_PIN_NO_GUP_WRITE.Quoted 7 lines
We want to longterm write-pin.
@Pankaj, how come you would call this "
FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
Quoted 6 lines
I based it on Gupta saying 'without kernel GUP writes, and therefore not impacting dirty tracking'
I mean I think we definitely need some clarification here yes :)
Not really got the bandwidth to dig deep into GUP again :P
I think the KVM gueest *will* write to these pages.
By disallowing writable LONGTERM pins on FSes we broke one existing use case that was relying on that to work.
Signature · 3 lines
Cheers, David
Sean Christopherson
maintainerQuoted 31 lines · David Hildenbrand (Arm)
Quoted 30 lines · Lorenzo Stoakes
Quoted 28 lines · David Hildenbrand (Arm)
Quoted 10 lines · Lorenzo Stoakes
OK as long as that's made clear in the patch, commit message, comments etc. :)
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Thanks!
Quoted 7 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)I'm confused about the
_READONLY, well. and theFOLL_PIN_NO_GUP_WRITE.We want to longterm write-pin.
@Pankaj, how come you would call this "
FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
Quoted 8 lines
Quoted 6 lines
I based it on Gupta saying 'without kernel GUP writes, and therefore not impacting dirty tracking'
I mean I think we definitely need some clarification here yes :)
Not really got the bandwidth to dig deep into GUP again :P
I think the KVM gueest *will* write to these pages.
Yes, the guest will write these pages, but through KVM's normal mechanism for mapping memory into guests. The host will NOT write this memory via the GUP pins though. KVM needs to pin the pages because the memory is (well, technically may be) encrypted (by the CPU) with a key that is only used/accessible when the guest is active, and the encryption is salted with the system physical address of the page. E.g. attempting to migrate the page would corrupt guest memory due to copying ciphertext that would decrypt different at the new PA.
Quoted 2 lines
By disallowing writable LONGTERM pins on FSes we broke one existing use case that was relying on that to work.
Lorenzo Stoakes
reviewerQuoted 41 lines · Sean Christopherson
Quoted 31 lines · David Hildenbrand (Arm)
Quoted 30 lines · Lorenzo Stoakes
Quoted 28 lines · David Hildenbrand (Arm)
Quoted 10 lines · Lorenzo Stoakes
OK as long as that's made clear in the patch, commit message, comments etc. :)
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Thanks!
Quoted 7 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)I'm confused about the
_READONLY, well. and theFOLL_PIN_NO_GUP_WRITE.We want to longterm write-pin.
@Pankaj, how come you would call this "
FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
Quoted 8 lines
Quoted 6 lines
I based it on Gupta saying 'without kernel GUP writes, and therefore not impacting dirty tracking'
I mean I think we definitely need some clarification here yes :)
Not really got the bandwidth to dig deep into GUP again :P
I think the KVM gueest *will* write to these pages.
Quoted 7 lines
Yes, the guest will write these pages, but through KVM's normal mechanism for mapping memory into guests. The host will NOT write this memory via the GUP pins though. KVM needs to pin the pages because the memory is (well, technically may be) encrypted (by the CPU) with a key that is only used/accessible when the guest is active, and the encryption is salted with the system physical address of the page. E.g. attempting to migrate the page would corrupt guest memory due to copying ciphertext that would decrypt different at the new PA.
OK so it's a pinky promise that you won't write to it via GUP?
It's still really crap to just allow drivers to ignore this, which is asking for abuse.
Is this something we could have a specific GUP helper for that is unexported? Or does a module have to use this?
If not could we use some whitelisted approach or something to prevent arbitrary drivers from overriding this?
Quoted 3 lines
Quoted 3 lines
By disallowing writable LONGTERM pins on FSes we broke one existing use case that was relying on that to work.
How long ago did I break this though? Why has it taken until now for this to be reported? :) commit 8ac268436e6d ("mm/gup: disallow FOLL_LONGTERM GUP-nonfast writing to file-backed mappings") is from May 2023 :)
Is it vendors moving slow to update distros? Does speak to the usefulness of testing mainline asap in any case.
I maybe missing details about the actual motivating issue here sorry!
Thanks, Lorenzo
Sean Christopherson
maintainerQuoted 50 lines · Lorenzo Stoakes
Quoted 41 lines · Sean Christopherson
Quoted 31 lines · David Hildenbrand (Arm)
Quoted 30 lines · Lorenzo Stoakes
Quoted 28 lines · David Hildenbrand (Arm)
Quoted 10 lines · Lorenzo Stoakes
OK as long as that's made clear in the patch, commit message, comments etc. :)
Ack yeah I assumed it was a quick proof of concept and just overlooked it :P
Thanks!
Quoted 7 lines
hmm but we have
FOLL_LONGTERMas an adjunct toFOLL_PIN(doesn't make sense without - any checks that exist for that btw should be extended to this noew flag).Also don't we want to encode the legacy aspect here?
Maybe
FOLL_LONGTERM_LEGACY_READONLY? Naming is hard :)I'm confused about the
_READONLY, well. and theFOLL_PIN_NO_GUP_WRITE.We want to longterm write-pin.
@Pankaj, how come you would call this "
FOLL_PIN_NO_GUP_WRITE" -- why "no GUP write" ?I agree that someting like FOLL_LONGTERM_LEGACY_* is the right thing to do, but I don't see where this is "no write" or "readonly" ?
Quoted 8 lines
Quoted 6 lines
I based it on Gupta saying 'without kernel GUP writes, and therefore not impacting dirty tracking'
I mean I think we definitely need some clarification here yes :)
Not really got the bandwidth to dig deep into GUP again :P
I think the KVM gueest *will* write to these pages.
Quoted 7 lines
Yes, the guest will write these pages, but through KVM's normal mechanism for mapping memory into guests. The host will NOT write this memory via the GUP pins though. KVM needs to pin the pages because the memory is (well, technically may be) encrypted (by the CPU) with a key that is only used/accessible when the guest is active, and the encryption is salted with the system physical address of the page. E.g. attempting to migrate the page would corrupt guest memory due to copying ciphertext that would decrypt different at the new PA.
Quoted 1 line
OK so it's a pinky promise that you won't write to it via GUP?
LOL, yep.
Quoted 2 lines
It's still really crap to just allow drivers to ignore this, which is asking for abuse.
Yes, the KVM API in question is garbage, and for all intents and purposes it's deprecated going forward, but unfortunately we're stuck with it.
Quoted 2 lines
Is this something we could have a specific GUP helper for that is unexported? Or does a module have to use this?
Module, but we can limit to KVM modules via EXPORT_SYMBOL_FOR_KVM(), which also discourages abuse by only providing the export if KVM is actually configured to be built as a module.
Quoted 10 lines
If not could we use some whitelisted approach or something to prevent arbitrary drivers from overriding this?
Quoted 3 lines
Quoted 3 lines
By disallowing writable LONGTERM pins on FSes we broke one existing use case that was relying on that to work.
How long ago did I break this though? Why has it taken until now for this to be reported? :) commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") is from May 2023 :)
The break didn't come from your changes, it came from commit 7e066cb9b71a ("KVM:
SEV: Use long-term pin when registering encrypted memory regions"). I suggested falling back to a non-longterm pin, but David didn't like that idea :-)
https://lore.kernel.org/all/[email protected]
Quoted 6 lines
Is it vendors moving slow to update distros? Does speak to the usefulness of testing mainline asap in any case.
I maybe missing details about the actual motivating issue here sorry!
Thanks, Lorenzo
David Hildenbrand (Arm)
maintainerQuoted 8 lines
Quoted 4 lines
How long ago did I break this though? Why has it taken until now for this to be reported? :) commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") is from May 2023 :)The break didn't come from your changes, it came from commit
7e066cb9b71a("KVM:
SEV: Use long-term pin when registering encrypted memory regions"). I suggested falling back to a non-longterm pin, but David didn't like that idea :-)
Yes, a longterm pin is a longterm pin.
If we don't write to the memory, why do we need a write pin? To make sure that what we pin was actually unshared?
Well, FOLL_LONGTERM does that nowadays.
... so is maybe dropping the FOLL_WRITE sufficient?
Signature · 3 lines
Cheers, David
Lorenzo Stoakes
reviewerQuoted 10 lines · David Hildenbrand (Arm)
Quoted 8 lines
Quoted 4 lines
How long ago did I break this though? Why has it taken until now for this to be reported? :) commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") is from May 2023 :)The break didn't come from your changes, it came from commit
7e066cb9b71a("KVM:
SEV: Use long-term pin when registering encrypted memory regions"). I suggested falling back to a non-longterm pin, but David didn't like that idea :-)Yes, a longterm pin is a longterm pin.
Yes it'd be very unwise to not use a longterm pin here!
Quoted 8 lines
If we don't write to the memory, why do we need a write pin? To make sure that what we pin was actually unshared?
Well,
FOLL_LONGTERMdoes that nowadays.... so is maybe dropping the
FOLL_WRITEsufficient?
That solves the whole thing, as the check is gated on FOLL_WRITE anyway.
I hadn't dug into the code enough there, been scanning.
So that's a simple fix then? :)
Quoted 5 lines
--
Cheers,David
Cheers, Lorenzo
Quoted 8 lines · David Hildenbrand (Arm)
Quoted 6 lines
Quoted 3 lines
How long ago did I break this though? Why has it taken until now for this to be reported? :) commit
8ac268436e6d("mm/gup: disallowFOLL_LONGTERMGUP-nonfast writing to file-backed mappings") is from May 2023 :)The break didn't come from your changes, it came from commit
7e066cb9b71a("KVM:
SEV: Use long-term pin when registering encrypted memory regions"). I suggested falling back to a non-longterm pin, but David didn't like that idea :-)Yes, a longterm pin is a longterm pin.
Quoted 7 lines
If we don't write to the memory, why do we need a write pin? To make sure that what we pin was actually unshared?
Well,
FOLL_LONGTERMdoes that nowadays.... so is maybe dropping the
FOLL_WRITEsufficient?
Yes, All that is correct. Sent a v2.
Thank you!
Pankaj