Here is the code to reproduce this bug:
unsigned int WIDTH = 1024;
unsigned int HEIGHT = 513;
unsigned int size = WIDTH * HEIGHT * 4;
int work(int vfd, int dfd, int handle) {
int ret;
struct drm_prime_handle hf = {.handle = handle };
ret = ioctl(dfd, DRM_IOCTL_PRIME_HANDLE_TO_FD, &hf);
fprintf(stderr, "fd is %d\n", hf.fd);
hf.flags = DRM_CLOEXEC | DRM_RDWR;
ret = ioctl(vfd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &hf);
fprintf(stderr, "new handle is %d\n", hf.handle);
struct drm_mode_map_dumb map = {.handle = hf.handle };
ret = ioctl(vfd, DRM_IOCTL_MODE_MAP_DUMB, &map);
fprintf(stderr, "need map at offset %lld\n", map.offset);
unsigned char * ptr = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_SHARED, vfd,
map.offset);
memset(ptr, 2, size);
munmap(ptr, size);
}
int main()
{
int vfd = open("/dev/dri/card0", O_RDWR); // vgem
int dfd = open("/dev/dri/card1", O_RDWR); // virtio gpu
int ret;
struct drm_mode_create_dumb ct = {};
ct.height = HEIGHT;
ct.width = WIDTH;
ct.bpp = 32;
ret = ioctl(dfd, DRM_IOCTL_MODE_CREATE_DUMB, &ct);
work(vfd, dfd, ct.handle);
fprintf(stderr, "done\n");
}
Signed-off-by: Lepton Wu <ytht.net@xxxxxxxxx>
---
drivers/gpu/drm/vgem/vgem_drv.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c
index ec1a8ebb6f1b..be3d97e29804 100644
--- a/drivers/gpu/drm/vgem/vgem_drv.c
+++ b/drivers/gpu/drm/vgem/vgem_drv.c
@@ -87,9 +87,8 @@ static vm_fault_t vgem_gem_fault(struct vm_fault *vmf)
mutex_lock(&obj->pages_lock);
if (obj->pages) {
- get_page(obj->pages[page_offset]);
- vmf->page = obj->pages[page_offset];
- ret = 0;
+ ret = vmf_insert_pfn(vmf->vma, vmf->address,
+ page_to_pfn(obj->pages[page_offset]));
}
mutex_unlock(&obj->pages_lock);
if (ret) {
@@ -263,7 +262,6 @@ static struct drm_ioctl_desc vgem_ioctls[] = {
static int vgem_mmap(struct file *filp, struct vm_area_struct *vma)
{
- unsigned long flags = vma->vm_flags;
int ret;
ret = drm_gem_mmap(filp, vma);
@@ -273,7 +271,6 @@ static int vgem_mmap(struct file *filp, struct vm_area_struct *vma)
/* Keep the WC mmaping set by drm_gem_mmap() but our pages
* are ordinary and not special.
*/
- vma->vm_flags = flags | VM_DONTEXPAND | VM_DONTDUMP;
return 0;
}
--
2.27.0.212.ge8ba1cc988-goog
_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&data=02%7C01%7Cchristian.koenig%40amd.com%7Cfc0831be8fd848abfd8908d82254266d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637297092113216357&sdata=C1sO1pUj0wnga%2BodcDRl9gA%2FNpIGO368KeQUAFyWK2g%3D&reserved=0