<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi Rob,<div class=""><br class=""></div><div class="">Yes, I’d completely missed the shrinker path in this cleanup. But, yeah, I see how get_pages (which is called with msm_obj->lock held) -> drm_gem_get_pages could trigger shrinker_scan which calls msm_gem_purge.</div><div class="">It makes sense to prevent any get_pages/vmap on objects that’ve been marked as DONTNEED. I’ll send you a patch soon for that.</div><div class=""><br class=""></div><div class="">Thanks,</div><div class="">Sushmita</div><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 14, 2017, at 10:49 AM, Rob Clark <<a href="mailto:robdclark@gmail.com" class="">robdclark@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Tue, Jun 13, 2017 at 6:52 PM, Sushmita Susheelendra</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><</span><a href="mailto:ssusheel@codeaurora.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">ssusheel@codeaurora.org</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">> wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">Buffer object specific resources like pages, domains, sg list<br class="">need not be protected with struct_mutex. They can be protected<br class="">with a buffer object level lock. This simplifies locking and<br class="">makes it easier to avoid potential recursive locking scenarios<br class="">for SVM involving mmap_sem and struct_mutex. This also removes<br class="">unnecessary serialization when creating buffer objects, and also<br class="">between buffer object creation and GPU command submission.<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I've rebased this on top of the other changes that are in the queue for 4.13:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://github.com/freedreno/kernel-msm/commit/4e0c4e139a647914cfcf7c413da5c19f9f124885" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">https://github.com/freedreno/kernel-msm/commit/4e0c4e139a647914cfcf7c413da5c19f9f124885</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I've done some light testing on a5xx.. although between this and</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">moving gpu->hw_init() under struct_mutex, I need to double check on</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">a3xx/a4xx.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I do think we probably need a bit more work for shrinker.  In</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">particular msm_gem_purge() still assumes everything is protected by a</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">single struct_mutex, which is no longer true.  The tricky thing here</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">is that shrinker can be triggered by code-paths where we already hold</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">msm_obj->lock.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">I think we probably want anything that ends up in get_pages() or</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">vmap() to have something along the lines of</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> if (WARN_ON(msm_obj->madv == DONTNEED)) {</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">   mutex_unlock(&msm_obj->lock);</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">   return -EINVAL;   // or -EBUSY, or ??</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""> }</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">it's really only something that a badly behaved userspace could</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">triger.. but otoh we probably don't want to let a badly behaved</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">userspace deadlock things in the kernel.  I guess I probably should</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">have written some test cases for this by now.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">Change-Id: I4fba9f8c38a6cd13f80f660639d1e74d4336e3fb<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">jfyi, no need for the Change-Id.. I usually strip them out when I</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">apply patches, but I appreciate if you can strip them out before</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">sending (because sometimes I forget)</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">BR,</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">-R</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">Signed-off-by: Sushmita Susheelendra <<a href="mailto:ssusheel@codeaurora.org" class="">ssusheel@codeaurora.org</a>><br class="">---<br class="">drivers/gpu/drm/msm/adreno/a5xx_gpu.c    |   2 -<br class="">drivers/gpu/drm/msm/adreno/a5xx_power.c  |   2 -<br class="">drivers/gpu/drm/msm/adreno/adreno_gpu.c  |   2 -<br class="">drivers/gpu/drm/msm/dsi/dsi_host.c       |   5 +-<br class="">drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c |   2 +-<br class="">drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.c  |   2 -<br class="">drivers/gpu/drm/msm/msm_drv.c            |   1 +<br class="">drivers/gpu/drm/msm/msm_drv.h            |   7 +-<br class="">drivers/gpu/drm/msm/msm_fbdev.c          |   6 +-<br class="">drivers/gpu/drm/msm/msm_gem.c            | 190 +++++++++++++++----------------<br class="">drivers/gpu/drm/msm/msm_gem.h            |   2 +<br class="">drivers/gpu/drm/msm/msm_gem_submit.c     |   6 +-<br class="">drivers/gpu/drm/msm/msm_gem_vma.c        |  10 +-<br class="">drivers/gpu/drm/msm/msm_gpu.c            |   4 +-<br class="">drivers/gpu/drm/msm/msm_rd.c             |   4 +-<br class="">drivers/gpu/drm/msm/msm_ringbuffer.c     |   2 +-<br class="">16 files changed, 120 insertions(+), 127 deletions(-)<br class=""><br class="">diff --git a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c<br class="">index 31a9bce..7893de1 100644<br class="">--- a/drivers/gpu/drm/msm/adreno/a5xx_gpu.c<br class="">+++ b/drivers/gpu/drm/msm/adreno/a5xx_gpu.c<br class="">@@ -235,9 +235,7 @@ static struct drm_gem_object *a5xx_ucode_load_bo(struct msm_gpu *gpu,<br class="">       struct drm_gem_object *bo;<br class="">       void *ptr;<br class=""><br class="">-       mutex_lock(&drm->struct_mutex);<br class="">       bo = msm_gem_new(drm, fw->size - 4, MSM_BO_UNCACHED);<br class="">-       mutex_unlock(&drm->struct_mutex);<br class=""><br class="">       if (IS_ERR(bo))<br class="">               return bo;<br class="">diff --git a/drivers/gpu/drm/msm/adreno/a5xx_power.c b/drivers/gpu/drm/msm/adreno/a5xx_power.c<br class="">index 72d52c7..eb88f44 100644<br class="">--- a/drivers/gpu/drm/msm/adreno/a5xx_power.c<br class="">+++ b/drivers/gpu/drm/msm/adreno/a5xx_power.c<br class="">@@ -294,9 +294,7 @@ void a5xx_gpmu_ucode_init(struct msm_gpu *gpu)<br class="">        */<br class="">       bosize = (cmds_size + (cmds_size / TYPE4_MAX_PAYLOAD) + 1) << 2;<br class=""><br class="">-       mutex_lock(&drm->struct_mutex);<br class="">       a5xx_gpu->gpmu_bo = msm_gem_new(drm, bosize, MSM_BO_UNCACHED);<br class="">-       mutex_unlock(&drm->struct_mutex);<br class=""><br class="">       if (IS_ERR(a5xx_gpu->gpmu_bo))<br class="">               goto err;<br class="">diff --git a/drivers/gpu/drm/msm/adreno/adreno_gpu.c b/drivers/gpu/drm/msm/adreno/adreno_gpu.c<br class="">index 5b63fc6..1162c15 100644<br class="">--- a/drivers/gpu/drm/msm/adreno/adreno_gpu.c<br class="">+++ b/drivers/gpu/drm/msm/adreno/adreno_gpu.c<br class="">@@ -392,10 +392,8 @@ int adreno_gpu_init(struct drm_device *drm, struct platform_device *pdev,<br class="">                       return ret;<br class="">       }<br class=""><br class="">-       mutex_lock(&drm->struct_mutex);<br class="">       adreno_gpu->memptrs_bo = msm_gem_new(drm, sizeof(*adreno_gpu->memptrs),<br class="">                       MSM_BO_UNCACHED);<br class="">-       mutex_unlock(&drm->struct_mutex);<br class="">       if (IS_ERR(adreno_gpu->memptrs_bo)) {<br class="">               ret = PTR_ERR(adreno_gpu->memptrs_bo);<br class="">               adreno_gpu->memptrs_bo = NULL;<br class="">diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c<br class="">index 4f79b10..6a1b0da 100644<br class="">--- a/drivers/gpu/drm/msm/dsi/dsi_host.c<br class="">+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c<br class="">@@ -980,19 +980,16 @@ static int dsi_tx_buf_alloc(struct msm_dsi_host *msm_host, int size)<br class="">       uint64_t iova;<br class=""><br class="">       if (cfg_hnd->major == MSM_DSI_VER_MAJOR_6G) {<br class="">-               mutex_lock(&dev->struct_mutex);<br class="">               msm_host->tx_gem_obj = msm_gem_new(dev, size, MSM_BO_UNCACHED);<br class="">               if (IS_ERR(msm_host->tx_gem_obj)) {<br class="">                       ret = PTR_ERR(msm_host->tx_gem_obj);<br class="">                       pr_err("%s: failed to allocate gem, %d\n",<br class="">                               __func__, ret);<br class="">                       msm_host->tx_gem_obj = NULL;<br class="">-                       mutex_unlock(&dev->struct_mutex);<br class="">                       return ret;<br class="">               }<br class=""><br class="">-               ret = msm_gem_get_iova_locked(msm_host->tx_gem_obj, 0, &iova);<br class="">-               mutex_unlock(&dev->struct_mutex);<br class="">+               ret = msm_gem_get_iova(msm_host->tx_gem_obj, 0, &iova);<br class="">               if (ret) {<br class="">                       pr_err("%s: failed to get iova, %d\n", __func__, ret);<br class="">                       return ret;<br class="">diff --git a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c<br class="">index f29194a..15478f8 100644<br class="">--- a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c<br class="">+++ b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c<br class="">@@ -372,7 +372,7 @@ static void update_cursor(struct drm_crtc *crtc)<br class="">               if (next_bo) {<br class="">                       /* take a obj ref + iova ref when we start scanning out: */<br class="">                       drm_gem_object_reference(next_bo);<br class="">-                       msm_gem_get_iova_locked(next_bo, mdp4_kms->id, &iova);<br class="">+                       msm_gem_get_iova(next_bo, mdp4_kms->id, &iova);<br class=""><br class="">                       /* enable cursor: */<br class="">                       mdp4_write(mdp4_kms, REG_MDP4_DMA_CURSOR_SIZE(dma),<br class="">diff --git a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.c b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.c<br class="">index 6295204..3a464b3 100644<br class="">--- a/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.c<br class="">+++ b/drivers/gpu/drm/msm/mdp/mdp4/mdp4_kms.c<br class="">@@ -561,9 +561,7 @@ struct msm_kms *mdp4_kms_init(struct drm_device *dev)<br class="">               goto fail;<br class="">       }<br class=""><br class="">-       mutex_lock(&dev->struct_mutex);<br class="">       mdp4_kms->blank_cursor_bo = msm_gem_new(dev, SZ_16K, MSM_BO_WC);<br class="">-       mutex_unlock(&dev->struct_mutex);<br class="">       if (IS_ERR(mdp4_kms->blank_cursor_bo)) {<br class="">               ret = PTR_ERR(mdp4_kms->blank_cursor_bo);<br class="">               dev_err(dev->dev, "could not allocate blank-cursor bo: %d\n", ret);<br class="">diff --git a/drivers/gpu/drm/msm/msm_drv.c b/drivers/gpu/drm/msm/msm_drv.c<br class="">index 87b5695..bb1f3ee 100644<br class="">--- a/drivers/gpu/drm/msm/msm_drv.c<br class="">+++ b/drivers/gpu/drm/msm/msm_drv.c<br class="">@@ -349,6 +349,7 @@ static int msm_init_vram(struct drm_device *dev)<br class="">               priv->vram.size = size;<br class=""><br class="">               drm_mm_init(&priv->vram.mm, 0, (size >> PAGE_SHIFT) - 1);<br class="">+               spin_lock_init(&priv->vram.lock);<br class=""><br class="">               attrs |= DMA_ATTR_NO_KERNEL_MAPPING;<br class="">               attrs |= DMA_ATTR_WRITE_COMBINE;<br class="">diff --git a/drivers/gpu/drm/msm/msm_drv.h b/drivers/gpu/drm/msm/msm_drv.h<br class="">index 28b6f9b..567737d 100644<br class="">--- a/drivers/gpu/drm/msm/msm_drv.h<br class="">+++ b/drivers/gpu/drm/msm/msm_drv.h<br class="">@@ -157,6 +157,7 @@ struct msm_drm_private {<br class="">                * and position mm_node->start is in # of pages:<br class="">                */<br class="">               struct drm_mm mm;<br class="">+               spinlock_t lock; /* Protects drm_mm node allocation/removal */<br class="">       } vram;<br class=""><br class="">       struct notifier_block vmap_notifier;<br class="">@@ -209,8 +210,6 @@ int msm_gem_mmap_obj(struct drm_gem_object *obj,<br class="">int msm_gem_mmap(struct file *filp, struct vm_area_struct *vma);<br class="">int msm_gem_fault(struct vm_fault *vmf);<br class="">uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj);<br class="">-int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,<br class="">-               uint64_t *iova);<br class="">int msm_gem_get_iova(struct drm_gem_object *obj, int id, uint64_t *iova);<br class="">uint64_t msm_gem_iova(struct drm_gem_object *obj, int id);<br class="">struct page **msm_gem_get_pages(struct drm_gem_object *obj);<br class="">@@ -228,9 +227,7 @@ struct drm_gem_object *msm_gem_prime_import_sg_table(struct drm_device *dev,<br class="">               struct dma_buf_attachment *attach, struct sg_table *sg);<br class="">int msm_gem_prime_pin(struct drm_gem_object *obj);<br class="">void msm_gem_prime_unpin(struct drm_gem_object *obj);<br class="">-void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj);<br class="">void *msm_gem_get_vaddr(struct drm_gem_object *obj);<br class="">-void msm_gem_put_vaddr_locked(struct drm_gem_object *obj);<br class="">void msm_gem_put_vaddr(struct drm_gem_object *obj);<br class="">int msm_gem_madvise(struct drm_gem_object *obj, unsigned madv);<br class="">void msm_gem_purge(struct drm_gem_object *obj);<br class="">@@ -247,6 +244,8 @@ int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,<br class="">               uint32_t size, uint32_t flags, uint32_t *handle);<br class="">struct drm_gem_object *msm_gem_new(struct drm_device *dev,<br class="">               uint32_t size, uint32_t flags);<br class="">+struct drm_gem_object *msm_gem_new_locked(struct drm_device *dev,<br class="">+               uint32_t size, uint32_t flags);<br class="">struct drm_gem_object *msm_gem_import(struct drm_device *dev,<br class="">               struct dma_buf *dmabuf, struct sg_table *sgt);<br class=""><br class="">diff --git a/drivers/gpu/drm/msm/msm_fbdev.c b/drivers/gpu/drm/msm/msm_fbdev.c<br class="">index 951e40f..785925e9 100644<br class="">--- a/drivers/gpu/drm/msm/msm_fbdev.c<br class="">+++ b/drivers/gpu/drm/msm/msm_fbdev.c<br class="">@@ -95,10 +95,8 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,<br class="">       /* allocate backing bo */<br class="">       size = mode_cmd.pitches[0] * mode_cmd.height;<br class="">       DBG("allocating %d bytes for fb %d", size, dev->primary->index);<br class="">-       mutex_lock(&dev->struct_mutex);<br class="">       fbdev->bo = msm_gem_new(dev, size, MSM_BO_SCANOUT |<br class="">                       MSM_BO_WC | MSM_BO_STOLEN);<br class="">-       mutex_unlock(&dev->struct_mutex);<br class="">       if (IS_ERR(fbdev->bo)) {<br class="">               ret = PTR_ERR(fbdev->bo);<br class="">               fbdev->bo = NULL;<br class="">@@ -124,7 +122,7 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,<br class="">        * in panic (ie. lock-safe, etc) we could avoid pinning the<br class="">        * buffer now:<br class="">        */<br class="">-       ret = msm_gem_get_iova_locked(fbdev->bo, 0, &paddr);<br class="">+       ret = msm_gem_get_iova(fbdev->bo, 0, &paddr);<br class="">       if (ret) {<br class="">               dev_err(dev->dev, "failed to get buffer obj iova: %d\n", ret);<br class="">               goto fail_unlock;<br class="">@@ -153,7 +151,7 @@ static int msm_fbdev_create(struct drm_fb_helper *helper,<br class=""><br class="">       dev->mode_config.fb_base = paddr;<br class=""><br class="">-       fbi->screen_base = msm_gem_get_vaddr_locked(fbdev->bo);<br class="">+       fbi->screen_base = msm_gem_get_vaddr(fbdev->bo);<br class="">       if (IS_ERR(fbi->screen_base)) {<br class="">               ret = PTR_ERR(fbi->screen_base);<br class="">               goto fail_unlock;<br class="">diff --git a/drivers/gpu/drm/msm/msm_gem.c b/drivers/gpu/drm/msm/msm_gem.c<br class="">index 68e509b..1e803fb 100644<br class="">--- a/drivers/gpu/drm/msm/msm_gem.c<br class="">+++ b/drivers/gpu/drm/msm/msm_gem.c<br class="">@@ -41,8 +41,7 @@ static bool use_pages(struct drm_gem_object *obj)<br class="">}<br class=""><br class="">/* allocate pages from VRAM carveout, used when no IOMMU: */<br class="">-static struct page **get_pages_vram(struct drm_gem_object *obj,<br class="">-               int npages)<br class="">+static struct page **get_pages_vram(struct drm_gem_object *obj, int npages)<br class="">{<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">       struct msm_drm_private *priv = obj->dev->dev_private;<br class="">@@ -54,7 +53,9 @@ static struct page **get_pages_vram(struct drm_gem_object *obj,<br class="">       if (!p)<br class="">               return ERR_PTR(-ENOMEM);<br class=""><br class="">+       spin_lock(&priv->vram.lock);<br class="">       ret = drm_mm_insert_node(&priv->vram.mm, msm_obj->vram_node, npages);<br class="">+       spin_unlock(&priv->vram.lock);<br class="">       if (ret) {<br class="">               drm_free_large(p);<br class="">               return ERR_PTR(ret);<br class="">@@ -69,7 +70,6 @@ static struct page **get_pages_vram(struct drm_gem_object *obj,<br class="">       return p;<br class="">}<br class=""><br class="">-/* called with dev->struct_mutex held */<br class="">static struct page **get_pages(struct drm_gem_object *obj)<br class="">{<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">@@ -109,6 +109,18 @@ static struct page **get_pages(struct drm_gem_object *obj)<br class="">       return msm_obj->pages;<br class="">}<br class=""><br class="">+static void put_pages_vram(struct drm_gem_object *obj)<br class="">+{<br class="">+       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">+       struct msm_drm_private *priv = obj->dev->dev_private;<br class="">+<br class="">+       spin_lock(&priv->vram.lock);<br class="">+       drm_mm_remove_node(msm_obj->vram_node);<br class="">+       spin_unlock(&priv->vram.lock);<br class="">+<br class="">+       drm_free_large(msm_obj->pages);<br class="">+}<br class="">+<br class="">static void put_pages(struct drm_gem_object *obj)<br class="">{<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">@@ -125,10 +137,8 @@ static void put_pages(struct drm_gem_object *obj)<br class=""><br class="">               if (use_pages(obj))<br class="">                       drm_gem_put_pages(obj, msm_obj->pages, true, false);<br class="">-               else {<br class="">-                       drm_mm_remove_node(msm_obj->vram_node);<br class="">-                       drm_free_large(msm_obj->pages);<br class="">-               }<br class="">+               else<br class="">+                       put_pages_vram(obj);<br class=""><br class="">               msm_obj->pages = NULL;<br class="">       }<br class="">@@ -136,11 +146,12 @@ static void put_pages(struct drm_gem_object *obj)<br class=""><br class="">struct page **msm_gem_get_pages(struct drm_gem_object *obj)<br class="">{<br class="">-       struct drm_device *dev = obj->dev;<br class="">+       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">       struct page **p;<br class="">-       mutex_lock(&dev->struct_mutex);<br class="">+<br class="">+       mutex_lock(&msm_obj->lock);<br class="">       p = get_pages(obj);<br class="">-       mutex_unlock(&dev->struct_mutex);<br class="">+       mutex_unlock(&msm_obj->lock);<br class="">       return p;<br class="">}<br class=""><br class="">@@ -195,25 +206,17 @@ int msm_gem_fault(struct vm_fault *vmf)<br class="">{<br class="">       struct vm_area_struct *vma = vmf->vma;<br class="">       struct drm_gem_object *obj = vma->vm_private_data;<br class="">-       struct drm_device *dev = obj->dev;<br class="">-       struct msm_drm_private *priv = dev->dev_private;<br class="">+       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">       struct page **pages;<br class="">       unsigned long pfn;<br class="">       pgoff_t pgoff;<br class="">       int ret;<br class=""><br class="">-       /* This should only happen if userspace tries to pass a mmap'd<br class="">-        * but unfaulted gem bo vaddr into submit ioctl, triggering<br class="">-        * a page fault while struct_mutex is already held.  This is<br class="">-        * not a valid use-case so just bail.<br class="">+       /*<br class="">+        * vm_ops.open/drm_gem_mmap_obj and close get and put<br class="">+        * a reference on obj. So, we dont need to hold one here.<br class="">        */<br class="">-       if (priv->struct_mutex_task == current)<br class="">-               return VM_FAULT_SIGBUS;<br class="">-<br class="">-       /* Make sure we don't parallel update on a fault, nor move or remove<br class="">-        * something from beneath our feet<br class="">-        */<br class="">-       ret = mutex_lock_interruptible(&dev->struct_mutex);<br class="">+       ret = mutex_lock_interruptible(&msm_obj->lock);<br class="">       if (ret)<br class="">               goto out;<br class=""><br class="">@@ -235,7 +238,7 @@ int msm_gem_fault(struct vm_fault *vmf)<br class="">       ret = vm_insert_mixed(vma, vmf->address, __pfn_to_pfn_t(pfn, PFN_DEV));<br class=""><br class="">out_unlock:<br class="">-       mutex_unlock(&dev->struct_mutex);<br class="">+       mutex_unlock(&msm_obj->lock);<br class="">out:<br class="">       switch (ret) {<br class="">       case -EAGAIN:<br class="">@@ -259,9 +262,10 @@ int msm_gem_fault(struct vm_fault *vmf)<br class="">static uint64_t mmap_offset(struct drm_gem_object *obj)<br class="">{<br class="">       struct drm_device *dev = obj->dev;<br class="">+       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">       int ret;<br class=""><br class="">-       WARN_ON(!mutex_is_locked(&dev->struct_mutex));<br class="">+       WARN_ON(!mutex_is_locked(&msm_obj->lock));<br class=""><br class="">       /* Make it mmapable */<br class="">       ret = drm_gem_create_mmap_offset(obj);<br class="">@@ -277,21 +281,23 @@ static uint64_t mmap_offset(struct drm_gem_object *obj)<br class="">uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj)<br class="">{<br class="">       uint64_t offset;<br class="">-       mutex_lock(&obj->dev->struct_mutex);<br class="">+       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">+<br class="">+       mutex_lock(&msm_obj->lock);<br class="">       offset = mmap_offset(obj);<br class="">-       mutex_unlock(&obj->dev->struct_mutex);<br class="">+       mutex_unlock(&msm_obj->lock);<br class="">       return offset;<br class="">}<br class=""><br class="">+/* Called with msm_obj->lock locked */<br class="">static void<br class="">put_iova(struct drm_gem_object *obj)<br class="">{<br class="">-       struct drm_device *dev = obj->dev;<br class="">       struct msm_drm_private *priv = obj->dev->dev_private;<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">       int id;<br class=""><br class="">-       WARN_ON(!mutex_is_locked(&dev->struct_mutex));<br class="">+       WARN_ON(!mutex_is_locked(&msm_obj->lock));<br class=""><br class="">       for (id = 0; id < ARRAY_SIZE(msm_obj->domain); id++) {<br class="">               if (!priv->aspace[id])<br class="">@@ -301,25 +307,23 @@ uint64_t msm_gem_mmap_offset(struct drm_gem_object *obj)<br class="">       }<br class="">}<br class=""><br class="">-/* should be called under struct_mutex.. although it can be called<br class="">- * from atomic context without struct_mutex to acquire an extra<br class="">- * iova ref if you know one is already held.<br class="">- *<br class="">- * That means when I do eventually need to add support for unpinning<br class="">- * the refcnt counter needs to be atomic_t.<br class="">- */<br class="">-int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,<br class="">+/* A reference to obj must be held before calling this function. */<br class="">+int msm_gem_get_iova(struct drm_gem_object *obj, int id,<br class="">               uint64_t *iova)<br class="">{<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">       int ret = 0;<br class=""><br class="">+       mutex_lock(&msm_obj->lock);<br class="">+<br class="">       if (!msm_obj->domain[id].iova) {<br class="">               struct msm_drm_private *priv = obj->dev->dev_private;<br class="">               struct page **pages = get_pages(obj);<br class=""><br class="">-               if (IS_ERR(pages))<br class="">+               if (IS_ERR(pages)) {<br class="">+                       mutex_unlock(&msm_obj->lock);<br class="">                       return PTR_ERR(pages);<br class="">+               }<br class=""><br class="">               if (iommu_present(&platform_bus_type)) {<br class="">                       ret = msm_gem_map_vma(priv->aspace[id], &msm_obj->domain[id],<br class="">@@ -332,26 +336,7 @@ int msm_gem_get_iova_locked(struct drm_gem_object *obj, int id,<br class="">       if (!ret)<br class="">               *iova = msm_obj->domain[id].iova;<br class=""><br class="">-       return ret;<br class="">-}<br class="">-<br class="">-/* get iova, taking a reference.  Should have a matching put */<br class="">-int msm_gem_get_iova(struct drm_gem_object *obj, int id, uint64_t *iova)<br class="">-{<br class="">-       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">-       int ret;<br class="">-<br class="">-       /* this is safe right now because we don't unmap until the<br class="">-        * bo is deleted:<br class="">-        */<br class="">-       if (msm_obj->domain[id].iova) {<br class="">-               *iova = msm_obj->domain[id].iova;<br class="">-               return 0;<br class="">-       }<br class="">-<br class="">-       mutex_lock(&obj->dev->struct_mutex);<br class="">-       ret = msm_gem_get_iova_locked(obj, id, iova);<br class="">-       mutex_unlock(&obj->dev->struct_mutex);<br class="">+       mutex_unlock(&msm_obj->lock);<br class="">       return ret;<br class="">}<br class=""><br class="">@@ -405,45 +390,37 @@ int msm_gem_dumb_map_offset(struct drm_file *file, struct drm_device *dev,<br class="">       return ret;<br class="">}<br class=""><br class="">-void *msm_gem_get_vaddr_locked(struct drm_gem_object *obj)<br class="">+void *msm_gem_get_vaddr(struct drm_gem_object *obj)<br class="">{<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">-       WARN_ON(!mutex_is_locked(&obj->dev->struct_mutex));<br class="">+<br class="">+       mutex_lock(&msm_obj->lock);<br class="">       if (!msm_obj->vaddr) {<br class="">               struct page **pages = get_pages(obj);<br class="">-               if (IS_ERR(pages))<br class="">+               if (IS_ERR(pages)) {<br class="">+                       mutex_unlock(&msm_obj->lock);<br class="">                       return ERR_CAST(pages);<br class="">+               }<br class="">               msm_obj->vaddr = vmap(pages, obj->size >> PAGE_SHIFT,<br class="">                               VM_MAP, pgprot_writecombine(PAGE_KERNEL));<br class="">-               if (msm_obj->vaddr == NULL)<br class="">+               if (msm_obj->vaddr == NULL) {<br class="">+                       mutex_unlock(&msm_obj->lock);<br class="">                       return ERR_PTR(-ENOMEM);<br class="">+               }<br class="">       }<br class="">       msm_obj->vmap_count++;<br class="">+       mutex_unlock(&msm_obj->lock);<br class="">       return msm_obj->vaddr;<br class="">}<br class=""><br class="">-void *msm_gem_get_vaddr(struct drm_gem_object *obj)<br class="">-{<br class="">-       void *ret;<br class="">-       mutex_lock(&obj->dev->struct_mutex);<br class="">-       ret = msm_gem_get_vaddr_locked(obj);<br class="">-       mutex_unlock(&obj->dev->struct_mutex);<br class="">-       return ret;<br class="">-}<br class="">-<br class="">-void msm_gem_put_vaddr_locked(struct drm_gem_object *obj)<br class="">+void msm_gem_put_vaddr(struct drm_gem_object *obj)<br class="">{<br class="">       struct msm_gem_object *msm_obj = to_msm_bo(obj);<br class="">-       WARN_ON(!mutex_is_locked(&obj->dev->struct_mutex));<br class="">+<br class="">+       mutex_lock(&msm_obj->lock);<br class="">       WARN_ON(msm_obj->vmap_count < 1);<br class="">       msm_obj->vmap_count--;<br class="">-}<br class="">-<br class="">-void msm_gem_put_vaddr(struct drm_gem_object *obj)<br class="">-{<br class="">-       mutex_lock(&obj->dev->struct_mutex);<br class="">-       msm_gem_put_vaddr_locked(obj);<br class="">-       mutex_unlock(&obj->dev->struct_mutex);<br class="">+       mutex_unlock(&msm_obj->lock);<br class="">}<br class=""><br class="">/* Update madvise status, returns true if not purged, else<br class="">@@ -697,6 +674,8 @@ void msm_gem_free_object(struct drm_gem_object *obj)<br class=""><br class="">       list_del(&msm_obj->mm_list);<br class=""><br class="">+       mutex_lock(&msm_obj->lock);<br class="">+<br class="">       put_iova(obj);<br class=""><br class="">       if (obj->import_attach) {<br class="">@@ -720,6 +699,7 @@ void msm_gem_free_object(struct drm_gem_object *obj)<br class=""><br class="">       drm_gem_object_release(obj);<br class=""><br class="">+       mutex_unlock(&msm_obj->lock);<br class="">       kfree(msm_obj);<br class="">}<br class=""><br class="">@@ -730,14 +710,8 @@ int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,<br class="">       struct drm_gem_object *obj;<br class="">       int ret;<br class=""><br class="">-       ret = mutex_lock_interruptible(&dev->struct_mutex);<br class="">-       if (ret)<br class="">-               return ret;<br class="">-<br class="">       obj = msm_gem_new(dev, size, flags);<br class=""><br class="">-       mutex_unlock(&dev->struct_mutex);<br class="">-<br class="">       if (IS_ERR(obj))<br class="">               return PTR_ERR(obj);<br class=""><br class="">@@ -752,7 +726,8 @@ int msm_gem_new_handle(struct drm_device *dev, struct drm_file *file,<br class="">static int msm_gem_new_impl(struct drm_device *dev,<br class="">               uint32_t size, uint32_t flags,<br class="">               struct reservation_object *resv,<br class="">-               struct drm_gem_object **obj)<br class="">+               struct drm_gem_object **obj,<br class="">+               bool struct_mutex_locked)<br class="">{<br class="">       struct msm_drm_private *priv = dev->dev_private;<br class="">       struct msm_gem_object *msm_obj;<br class="">@@ -781,6 +756,8 @@ static int msm_gem_new_impl(struct drm_device *dev,<br class="">       if (!msm_obj)<br class="">               return -ENOMEM;<br class=""><br class="">+       mutex_init(&msm_obj->lock);<br class="">+<br class="">       if (use_vram)<br class="">               msm_obj->vram_node = &msm_obj->domain[0].node;<br class=""><br class="">@@ -795,21 +772,25 @@ static int msm_gem_new_impl(struct drm_device *dev,<br class="">       }<br class=""><br class="">       INIT_LIST_HEAD(&msm_obj->submit_entry);<br class="">-       list_add_tail(&msm_obj->mm_list, &priv->inactive_list);<br class="">+       if (struct_mutex_locked) {<br class="">+               list_add_tail(&msm_obj->mm_list, &priv->inactive_list);<br class="">+       } else {<br class="">+               mutex_lock(&dev->struct_mutex);<br class="">+               list_add_tail(&msm_obj->mm_list, &priv->inactive_list);<br class="">+               mutex_unlock(&dev->struct_mutex);<br class="">+       }<br class=""><br class="">       *obj = &msm_obj->base;<br class=""><br class="">       return 0;<br class="">}<br class=""><br class="">-struct drm_gem_object *msm_gem_new(struct drm_device *dev,<br class="">-               uint32_t size, uint32_t flags)<br class="">+static struct drm_gem_object *_msm_gem_new(struct drm_device *dev,<br class="">+               uint32_t size, uint32_t flags, bool struct_mutex_locked)<br class="">{<br class="">       struct drm_gem_object *obj = NULL;<br class="">       int ret;<br class=""><br class="">-       WARN_ON(!mutex_is_locked(&dev->struct_mutex));<br class="">-<br class="">       size = PAGE_ALIGN(size);<br class=""><br class="">       /* Disallow zero sized objects as they make the underlying<br class="">@@ -818,7 +799,7 @@ struct drm_gem_object *msm_gem_new(struct drm_device *dev,<br class="">       if (size == 0)<br class="">               return ERR_PTR(-EINVAL);<br class=""><br class="">-       ret = msm_gem_new_impl(dev, size, flags, NULL, &obj);<br class="">+       ret = msm_gem_new_impl(dev, size, flags, NULL, &obj, struct_mutex_locked);<br class="">       if (ret)<br class="">               goto fail;<br class=""><br class="">@@ -833,10 +814,22 @@ struct drm_gem_object *msm_gem_new(struct drm_device *dev,<br class="">       return obj;<br class=""><br class="">fail:<br class="">-       drm_gem_object_unreference(obj);<br class="">+       drm_gem_object_unreference_unlocked(obj);<br class="">       return ERR_PTR(ret);<br class="">}<br class=""><br class="">+struct drm_gem_object *msm_gem_new_locked(struct drm_device *dev,<br class="">+               uint32_t size, uint32_t flags)<br class="">+{<br class="">+       return _msm_gem_new(dev, size, flags, true);<br class="">+}<br class="">+<br class="">+struct drm_gem_object *msm_gem_new(struct drm_device *dev,<br class="">+               uint32_t size, uint32_t flags)<br class="">+{<br class="">+       return _msm_gem_new(dev, size, flags, false);<br class="">+}<br class="">+<br class="">struct drm_gem_object *msm_gem_import(struct drm_device *dev,<br class="">               struct dma_buf *dmabuf, struct sg_table *sgt)<br class="">{<br class="">@@ -853,7 +846,7 @@ struct drm_gem_object *msm_gem_import(struct drm_device *dev,<br class=""><br class="">       size = PAGE_ALIGN(dmabuf->size);<br class=""><br class="">-       ret = msm_gem_new_impl(dev, size, MSM_BO_WC, dmabuf->resv, &obj);<br class="">+       ret = msm_gem_new_impl(dev, size, MSM_BO_WC, dmabuf->resv, &obj, false);<br class="">       if (ret)<br class="">               goto fail;<br class=""><br class="">@@ -862,17 +855,22 @@ struct drm_gem_object *msm_gem_import(struct drm_device *dev,<br class="">       npages = size / PAGE_SIZE;<br class=""><br class="">       msm_obj = to_msm_bo(obj);<br class="">+       mutex_lock(&msm_obj->lock);<br class="">       msm_obj->sgt = sgt;<br class="">       msm_obj->pages = drm_malloc_ab(npages, sizeof(struct page *));<br class="">       if (!msm_obj->pages) {<br class="">+               mutex_unlock(&msm_obj->lock);<br class="">               ret = -ENOMEM;<br class="">               goto fail;<br class="">       }<br class=""><br class="">       ret = drm_prime_sg_to_page_addr_arrays(sgt, msm_obj->pages, NULL, npages);<br class="">-       if (ret)<br class="">+       if (ret) {<br class="">+               mutex_unlock(&msm_obj->lock);<br class="">               goto fail;<br class="">+       }<br class=""><br class="">+       mutex_unlock(&msm_obj->lock);<br class="">       return obj;<br class=""><br class="">fail:<br class="">diff --git a/drivers/gpu/drm/msm/msm_gem.h b/drivers/gpu/drm/msm/msm_gem.h<br class="">index 1b4cf20..b1bfc10 100644<br class="">--- a/drivers/gpu/drm/msm/msm_gem.h<br class="">+++ b/drivers/gpu/drm/msm/msm_gem.h<br class="">@@ -31,6 +31,7 @@ struct msm_gem_address_space {<br class="">        * and position mm_node->start is in # of pages:<br class="">        */<br class="">       struct drm_mm mm;<br class="">+       spinlock_t lock; /* Protects drm_mm node allocation/removal */<br class="">       struct msm_mmu *mmu;<br class="">       struct kref kref;<br class="">};<br class="">@@ -87,6 +88,7 @@ struct msm_gem_object {<br class="">        * an IOMMU.  Also used for stolen/splashscreen buffer.<br class="">        */<br class="">       struct drm_mm_node *vram_node;<br class="">+       struct mutex lock; /* Protects resources associated with bo */<br class="">};<br class="">#define to_msm_bo(x) container_of(x, struct msm_gem_object, base)<br class=""><br class="">diff --git a/drivers/gpu/drm/msm/msm_gem_submit.c b/drivers/gpu/drm/msm/msm_gem_submit.c<br class="">index 1c545eb..8420551 100644<br class="">--- a/drivers/gpu/drm/msm/msm_gem_submit.c<br class="">+++ b/drivers/gpu/drm/msm/msm_gem_submit.c<br class="">@@ -245,7 +245,7 @@ static int submit_pin_objects(struct msm_gem_submit *submit)<br class="">               uint64_t iova;<br class=""><br class="">               /* if locking succeeded, pin bo: */<br class="">-               ret = msm_gem_get_iova_locked(&msm_obj->base,<br class="">+               ret = msm_gem_get_iova(&msm_obj->base,<br class="">                               submit->gpu->id, &iova);<br class=""><br class="">               if (ret)<br class="">@@ -301,7 +301,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob<br class="">       /* For now, just map the entire thing.  Eventually we probably<br class="">        * to do it page-by-page, w/ kmap() if not vmap()d..<br class="">        */<br class="">-       ptr = msm_gem_get_vaddr_locked(&obj->base);<br class="">+       ptr = msm_gem_get_vaddr(&obj->base);<br class=""><br class="">       if (IS_ERR(ptr)) {<br class="">               ret = PTR_ERR(ptr);<br class="">@@ -359,7 +359,7 @@ static int submit_reloc(struct msm_gem_submit *submit, struct msm_gem_object *ob<br class="">       }<br class=""><br class="">out:<br class="">-       msm_gem_put_vaddr_locked(&obj->base);<br class="">+       msm_gem_put_vaddr(&obj->base);<br class=""><br class="">       return ret;<br class="">}<br class="">diff --git a/drivers/gpu/drm/msm/msm_gem_vma.c b/drivers/gpu/drm/msm/msm_gem_vma.c<br class="">index f285d7e..c36321bc 100644<br class="">--- a/drivers/gpu/drm/msm/msm_gem_vma.c<br class="">+++ b/drivers/gpu/drm/msm/msm_gem_vma.c<br class="">@@ -50,7 +50,9 @@ void msm_gem_address_space_put(struct msm_gem_address_space *aspace)<br class="">               aspace->mmu->funcs->unmap(aspace->mmu, vma->iova, sgt, size);<br class="">       }<br class=""><br class="">+       spin_lock(&aspace->lock);<br class="">       drm_mm_remove_node(&vma->node);<br class="">+       spin_unlock(&aspace->lock);<br class=""><br class="">       vma->iova = 0;<br class=""><br class="">@@ -63,10 +65,15 @@ void msm_gem_address_space_put(struct msm_gem_address_space *aspace)<br class="">{<br class="">       int ret;<br class=""><br class="">-       if (WARN_ON(drm_mm_node_allocated(&vma->node)))<br class="">+       spin_lock(&aspace->lock);<br class="">+       if (WARN_ON(drm_mm_node_allocated(&vma->node))) {<br class="">+               spin_unlock(&aspace->lock);<br class="">               return 0;<br class="">+       }<br class=""><br class="">       ret = drm_mm_insert_node(&aspace->mm, &vma->node, npages);<br class="">+       spin_unlock(&aspace->lock);<br class="">+<br class="">       if (ret)<br class="">               return ret;<br class=""><br class="">@@ -94,6 +101,7 @@ struct msm_gem_address_space *<br class="">       if (!aspace)<br class="">               return ERR_PTR(-ENOMEM);<br class=""><br class="">+       spin_lock_init(&aspace->lock);<br class="">       aspace->name = name;<br class="">       aspace->mmu = msm_iommu_new(dev, domain);<br class=""><br class="">diff --git a/drivers/gpu/drm/msm/msm_gpu.c b/drivers/gpu/drm/msm/msm_gpu.c<br class="">index 97b9c38..d6e5cb2 100644<br class="">--- a/drivers/gpu/drm/msm/msm_gpu.c<br class="">+++ b/drivers/gpu/drm/msm/msm_gpu.c<br class="">@@ -495,7 +495,7 @@ void msm_gpu_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit,<br class=""><br class="">               /* submit takes a reference to the bo and iova until retired: */<br class="">               drm_gem_object_reference(&msm_obj->base);<br class="">-               msm_gem_get_iova_locked(&msm_obj->base,<br class="">+               msm_gem_get_iova(&msm_obj->base,<br class="">                               submit->gpu->id, &iova);<br class=""><br class="">               if (submit->bos[i].flags & MSM_SUBMIT_BO_WRITE)<br class="">@@ -662,9 +662,7 @@ int msm_gpu_init(struct drm_device *drm, struct platform_device *pdev,<br class=""><br class=""><br class="">       /* Create ringbuffer: */<br class="">-       mutex_lock(&drm->struct_mutex);<br class="">       gpu->rb = msm_ringbuffer_new(gpu, ringsz);<br class="">-       mutex_unlock(&drm->struct_mutex);<br class="">       if (IS_ERR(gpu->rb)) {<br class="">               ret = PTR_ERR(gpu->rb);<br class="">               gpu->rb = NULL;<br class="">diff --git a/drivers/gpu/drm/msm/msm_rd.c b/drivers/gpu/drm/msm/msm_rd.c<br class="">index 0e81faa..0366b80 100644<br class="">--- a/drivers/gpu/drm/msm/msm_rd.c<br class="">+++ b/drivers/gpu/drm/msm/msm_rd.c<br class="">@@ -268,7 +268,7 @@ static void snapshot_buf(struct msm_rd_state *rd,<br class="">       struct msm_gem_object *obj = submit->bos[idx].obj;<br class="">       const char *buf;<br class=""><br class="">-       buf = msm_gem_get_vaddr_locked(&obj->base);<br class="">+       buf = msm_gem_get_vaddr(&obj->base);<br class="">       if (IS_ERR(buf))<br class="">               return;<br class=""><br class="">@@ -283,7 +283,7 @@ static void snapshot_buf(struct msm_rd_state *rd,<br class="">                       (uint32_t[3]){ iova, size, iova >> 32 }, 12);<br class="">       rd_write_section(rd, RD_BUFFER_CONTENTS, buf, size);<br class=""><br class="">-       msm_gem_put_vaddr_locked(&obj->base);<br class="">+       msm_gem_put_vaddr(&obj->base);<br class="">}<br class=""><br class="">/* called under struct_mutex */<br class="">diff --git a/drivers/gpu/drm/msm/msm_ringbuffer.c b/drivers/gpu/drm/msm/msm_ringbuffer.c<br class="">index 67b34e0..791bca3 100644<br class="">--- a/drivers/gpu/drm/msm/msm_ringbuffer.c<br class="">+++ b/drivers/gpu/drm/msm/msm_ringbuffer.c<br class="">@@ -40,7 +40,7 @@ struct msm_ringbuffer *msm_ringbuffer_new(struct msm_gpu *gpu, int size)<br class="">               goto fail;<br class="">       }<br class=""><br class="">-       ring->start = msm_gem_get_vaddr_locked(ring->bo);<br class="">+       ring->start = msm_gem_get_vaddr(ring->bo);<br class="">       if (IS_ERR(ring->start)) {<br class="">               ret = PTR_ERR(ring->start);<br class="">               goto fail;<br class="">--<br class="">1.9.1<br class=""><br class="">--<br class="">To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in<br class="">the body of a message to<span class="Apple-converted-space"> </span><a href="mailto:majordomo@vger.kernel.org" class="">majordomo@vger.kernel.org</a><br class="">More majordomo info at  <a href="http://vger.kernel.org/majordomo-info.html" class="">http://vger.kernel.org/majordomo-info.html</a></blockquote></div></blockquote></div><br class=""></div></body></html>