From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>,
Dave Hansen <dave.hansen@linux.intel.com>,
Andy Lutomirski <luto@kernel.org>,
Peter Zijlstra <peterz@infradead.org>, Fei Li <fei1.li@intel.com>
Cc: x86@kernel.org, linux-mm@kvack.org
Subject: [PATCH 1/3] virt: acrn: stop using follow_pfn
Date: Mon, 25 Mar 2024 07:45:40 +0800 [thread overview]
Message-ID: <20240324234542.2038726-2-hch@lst.de> (raw)
In-Reply-To: <20240324234542.2038726-1-hch@lst.de>
Switch from follow_pfn to follow_pte so that we can get rid of
follow_pfn. Note that this doesn't fix any of the pre-existing
raciness and lack of permission checking in the code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/virt/acrn/mm.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/drivers/virt/acrn/mm.c b/drivers/virt/acrn/mm.c
index fa5d9ca6be5706..69c3f619f88196 100644
--- a/drivers/virt/acrn/mm.c
+++ b/drivers/virt/acrn/mm.c
@@ -171,18 +171,24 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap)
mmap_read_lock(current->mm);
vma = vma_lookup(current->mm, memmap->vma_base);
if (vma && ((vma->vm_flags & VM_PFNMAP) != 0)) {
+ spinlock_t *ptl;
+ pte_t *ptep;
+
if ((memmap->vma_base + memmap->len) > vma->vm_end) {
mmap_read_unlock(current->mm);
return -EINVAL;
}
- ret = follow_pfn(vma, memmap->vma_base, &pfn);
- mmap_read_unlock(current->mm);
+ ret = follow_pte(vma->vm_mm, memmap->vma_base, &ptep, &ptl);
if (ret < 0) {
+ mmap_read_unlock(current->mm);
dev_dbg(acrn_dev.this_device,
"Failed to lookup PFN at VMA:%pK.\n", (void *)memmap->vma_base);
return ret;
}
+ pfn = pte_pfn(ptep_get(ptep));
+ pte_unmap_unlock(ptep, ptl);
+ mmap_read_unlock(current->mm);
return acrn_mm_region_add(vm, memmap->user_vm_pa,
PFN_PHYS(pfn), memmap->len,
--
2.39.2
next prev parent reply other threads:[~2024-03-24 23:45 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-24 23:45 remove follow_pfn Christoph Hellwig
2024-03-24 23:45 ` Christoph Hellwig [this message]
2024-03-25 10:33 ` [PATCH 1/3] virt: acrn: stop using follow_pfn David Hildenbrand
2024-03-26 6:04 ` Christoph Hellwig
2024-03-26 17:06 ` David Hildenbrand
2024-03-24 23:45 ` [PATCH 2/3] mm: remove follow_pfn Christoph Hellwig
2024-03-25 10:33 ` David Hildenbrand
2024-03-24 23:45 ` [PATCH 3/3] mm: move follow_phys to arch/x86/mm/pat/memtype.c Christoph Hellwig
2024-03-25 10:28 ` Ingo Molnar
2024-03-25 10:36 ` David Hildenbrand
2024-03-28 8:46 remove follow_pfn v2 Christoph Hellwig
2024-03-28 8:46 ` [PATCH 1/3] virt: acrn: stop using follow_pfn Christoph Hellwig
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=20240324234542.2038726-2-hch@lst.de \
--to=hch@lst.de \
--cc=akpm@linux-foundation.org \
--cc=dave.hansen@linux.intel.com \
--cc=fei1.li@intel.com \
--cc=linux-mm@kvack.org \
--cc=luto@kernel.org \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
/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.