Skip to content

Commit 8a6e85f

Browse files
yonghuahgregkh
authored andcommitted
virt: acrn: obtain pa from VMA with PFNMAP flag
acrn_vm_ram_map can't pin the user pages with VM_PFNMAP flag by calling get_user_pages_fast(), the PA(physical pages) may be mapped by kernel driver and set PFNMAP flag. This patch fixes logic to setup EPT mapping for PFN mapped RAM region by checking the memory attribute before adding EPT mapping for them. Fixes: 88f537d ("virt: acrn: Introduce EPT mapping management") Signed-off-by: Yonghua Huang <[email protected]> Signed-off-by: Fei Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fbeac3d commit 8a6e85f

File tree

1 file changed

+24
-0
lines changed
  • drivers/virt/acrn

1 file changed

+24
-0
lines changed

drivers/virt/acrn/mm.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,34 @@ int acrn_vm_ram_map(struct acrn_vm *vm, struct acrn_vm_memmap *memmap)
162162
void *remap_vaddr;
163163
int ret, pinned;
164164
u64 user_vm_pa;
165+
unsigned long pfn;
166+
struct vm_area_struct *vma;
165167

166168
if (!vm || !memmap)
167169
return -EINVAL;
168170

171+
mmap_read_lock(current->mm);
172+
vma = vma_lookup(current->mm, memmap->vma_base);
173+
if (vma && ((vma->vm_flags & VM_PFNMAP) != 0)) {
174+
if ((memmap->vma_base + memmap->len) > vma->vm_end) {
175+
mmap_read_unlock(current->mm);
176+
return -EINVAL;
177+
}
178+
179+
ret = follow_pfn(vma, memmap->vma_base, &pfn);
180+
mmap_read_unlock(current->mm);
181+
if (ret < 0) {
182+
dev_dbg(acrn_dev.this_device,
183+
"Failed to lookup PFN at VMA:%pK.\n", (void *)memmap->vma_base);
184+
return ret;
185+
}
186+
187+
return acrn_mm_region_add(vm, memmap->user_vm_pa,
188+
PFN_PHYS(pfn), memmap->len,
189+
ACRN_MEM_TYPE_WB, memmap->attr);
190+
}
191+
mmap_read_unlock(current->mm);
192+
169193
/* Get the page number of the map region */
170194
nr_pages = memmap->len >> PAGE_SHIFT;
171195
pages = vzalloc(nr_pages * sizeof(struct page *));

0 commit comments

Comments
 (0)