Re: [PATCH 0/6] KVM: Remove uses of struct page from x86 and arm64 MMU

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]


On 24/06/21 13:42, Nicholas Piggin wrote:
+static int kvm_try_get_pfn(kvm_pfn_t pfn)
+	if (kvm_is_reserved_pfn(pfn))
+		return 1;

So !pfn_valid would always return true. Yeah, this should work and is certainly appealing!


+	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;
  	pte_unmap_unlock(ptep, ptl);
  	*p_pfn = pfn;
-	return 0;
+	return r;

[Index of Archives]     [KVM Development]     [KVM ARM]     [KVM ia64]     [Linux Virtualization]     [Linux USB Devel]     [Linux Video]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux