From: Jun Chen <jun.d.chen@intel.com>
To: airlied@linux.ie, viro@zeniv.linux.org.uk, airlied@redhat.com
Cc: dri-devel@lists.freedesktop.org,
Linux Kernel <linux-kernel@vger.kernel.org>,
Jun Chen <jun.d.chen@intel.com>
Subject: [PATCH] drm: Add the mutex protection in drm_do_vm_fault.
Date: Fri, 11 Oct 2013 11:47:30 -0400 [thread overview]
Message-ID: <1381506450.7844.4.camel@chenjun-workstation> (raw)
There are no mutex protection for the dev->map_hash while calling
the drm_ht_find_item in the function drm_do_vm_fault. So try to
mutex firstly and then find the list for using to avoid this race
condition.
Signed-off-by: Chen Jun <jun.d.chen@intel.com>
---
drivers/gpu/drm/drm_vm.c | 11 +++++++++--
1 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/drm_vm.c b/drivers/gpu/drm/drm_vm.c
index b5c5af7..1d95221 100644
--- a/drivers/gpu/drm/drm_vm.c
+++ b/drivers/gpu/drm/drm_vm.c
@@ -107,8 +107,11 @@ static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
if (!dev->agp || !dev->agp->cant_use_aperture)
goto vm_fault_error;
- if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash))
+ mutex_lock(&dev->struct_mutex);
+ if (drm_ht_find_item(&dev->map_hash, vma->vm_pgoff, &hash)) {
+ mutex_unlock(&dev->struct_mutex);
goto vm_fault_error;
+ }
r_list = drm_hash_entry(hash, struct drm_map_list, hash);
map = r_list->map;
@@ -140,8 +143,10 @@ static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
break;
}
- if (&agpmem->head == &dev->agp->memory)
+ if (&agpmem->head == &dev->agp->memory) {
+ mutex_unlock(&dev->struct_mutex);
goto vm_fault_error;
+ }
/*
* Get the page, inc the use count, and return it
@@ -151,6 +156,7 @@ static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
get_page(page);
vmf->page = page;
+ mutex_unlock(&dev->struct_mutex);
DRM_DEBUG
("baddr = 0x%llx page = 0x%p, offset = 0x%llx, count=%d\n",
(unsigned long long)baddr,
@@ -159,6 +165,7 @@ static int drm_do_vm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
page_count(page));
return 0;
}
+ mutex_unlock(&dev->struct_mutex);
vm_fault_error:
return VM_FAULT_SIGBUS; /* Disallow mremap */
}
--
1.7.4.1
next reply other threads:[~2013-10-11 7:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-10-11 15:47 Jun Chen [this message]
2013-11-06 3:33 ` [PATCH] drm: Add the mutex protection in drm_do_vm_fault Dave Airlie
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=1381506450.7844.4.camel@chenjun-workstation \
--to=jun.d.chen@intel.com \
--cc=airlied@linux.ie \
--cc=airlied@redhat.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox