mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-01 16:14:13 +08:00
A selftests fix for ARM, and the fix for page reference count underflow.
This is a very small fix that was provided by Nick Piggin and tested by myself. -----BEGIN PGP SIGNATURE----- iQFIBAABCAAyFiEE8TM4V0tmI4mGbHaCv/vSX3jHroMFAmDU+IYUHHBib256aW5p QHJlZGhhdC5jb20ACgkQv/vSX3jHroPNRggAj286k4/wI4bCFw4cB8MkuJc0hgYm H22SuYjUsBwaxUPCYijRxshlq1nP21I05bJKHY1OpZPkEVyOd8MufC6Jc7YOENni f0nmZRmRpgmKuIEnwLoLra17MpZn3qFOkWwfmmNLgtLX2CRaHbhq3gZpX2V3mP7J qsepe0s65cCEbA0yC0+oMuS9JHAv7RjfDKM+3dOgE1pH83lv9UqF7W0WJfc0d7z0 KDPCLgU4Qa2rst/yPKwt/IFuzF8PBIwwYkYOZ/UrxKyZcUZGIHHyy0yWSywXIzcU 8zXl8AlUokadoqaGAP4qIaspDZWCIVA+S4X4y2Ly0CtExtfsh+27ww8eiQ== =bjxg -----END PGP SIGNATURE----- Merge tag 'for-linus-urgent' of git://git.kernel.org/pub/scm/virt/kvm/kvm Pull kvm fixes from Paolo Bonzini: "A selftests fix for ARM, and the fix for page reference count underflow. This is a very small fix that was provided by Nick Piggin and tested by myself" * tag 'for-linus-urgent' of git://git.kernel.org/pub/scm/virt/kvm/kvm: KVM: do not allow mapping valid but non-reference-counted pages KVM: selftests: Fix mapping length truncation in m{,un}map()
This commit is contained in:
commit
616a99dd14
@ -376,7 +376,7 @@ static void test_add_max_memory_regions(void)
|
||||
pr_info("Adding slots 0..%i, each memory region with %dK size\n",
|
||||
(max_mem_slots - 1), MEM_REGION_SIZE >> 10);
|
||||
|
||||
mem = mmap(NULL, MEM_REGION_SIZE * max_mem_slots + alignment,
|
||||
mem = mmap(NULL, (size_t)max_mem_slots * MEM_REGION_SIZE + alignment,
|
||||
PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||
TEST_ASSERT(mem != MAP_FAILED, "Failed to mmap() host");
|
||||
mem_aligned = (void *)(((size_t) mem + alignment - 1) & ~(alignment - 1));
|
||||
@ -401,7 +401,7 @@ static void test_add_max_memory_regions(void)
|
||||
TEST_ASSERT(ret == -1 && errno == EINVAL,
|
||||
"Adding one more memory slot should fail with EINVAL");
|
||||
|
||||
munmap(mem, MEM_REGION_SIZE * max_mem_slots + alignment);
|
||||
munmap(mem, (size_t)max_mem_slots * MEM_REGION_SIZE + alignment);
|
||||
munmap(mem_extra, MEM_REGION_SIZE);
|
||||
kvm_vm_free(vm);
|
||||
}
|
||||
|
@ -2055,6 +2055,13 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int kvm_try_get_pfn(kvm_pfn_t pfn)
|
||||
{
|
||||
if (kvm_is_reserved_pfn(pfn))
|
||||
return 1;
|
||||
return get_page_unless_zero(pfn_to_page(pfn));
|
||||
}
|
||||
|
||||
static int hva_to_pfn_remapped(struct vm_area_struct *vma,
|
||||
unsigned long addr, bool *async,
|
||||
bool write_fault, bool *writable,
|
||||
@ -2104,13 +2111,21 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma,
|
||||
* Whoever called remap_pfn_range is also going to call e.g.
|
||||
* unmap_mapping_range before the underlying pages are freed,
|
||||
* causing a call to our MMU notifier.
|
||||
*
|
||||
* Certain IO or PFNMAP mappings can be backed with valid
|
||||
* struct pages, but be allocated without refcounting e.g.,
|
||||
* tail pages of non-compound higher order allocations, which
|
||||
* would then underflow the refcount when the caller does the
|
||||
* required put_page. Don't allow those pages here.
|
||||
*/
|
||||
kvm_get_pfn(pfn);
|
||||
if (!kvm_try_get_pfn(pfn))
|
||||
r = -EFAULT;
|
||||
|
||||
out:
|
||||
pte_unmap_unlock(ptep, ptl);
|
||||
*p_pfn = pfn;
|
||||
return 0;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user