<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 2022-03-21 4:07 a.m., Thomas
      Hellström wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:b986f2a7-c0d3-b145-dd45-54d25e10a8be@linux.intel.com">
      <br>
      On 3/21/22 11:30, Tvrtko Ursulin wrote:
      <br>
      <blockquote type="cite">
        <br>
        On 19/03/2022 19:42, Michael Cheng wrote:
        <br>
        <blockquote type="cite">Previous concern with using
          drm_clflush_sg was that we don't know what the
          <br>
          sg_table is pointing to, thus the usage of wbinvd_on_all_cpus
          to flush
          <br>
          everything at once to avoid paranoia.
          <br>
        </blockquote>
        <br>
        And now we know, or we know it is not a concern?
        <br>
        <br>
        <blockquote type="cite">To make i915 more architecture-neutral
          and be less paranoid, lets attempt to
          <br>
        </blockquote>
        <br>
        "Lets attempt" as we don't know if this will work and/or what
        can/will break?
        <br>
        <br>
        <blockquote type="cite">use drm_clflush_sg to flush the pages
          for when the GPU wants to read
          <br>
          from main memory.
          <br>
          <br>
          Signed-off-by: Michael Cheng <a class="moz-txt-link-rfc2396E" href="mailto:michael.cheng@intel.com"><michael.cheng@intel.com></a>
          <br>
          ---
          <br>
            drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c | 9 ++-------
          <br>
            1 file changed, 2 insertions(+), 7 deletions(-)
          <br>
          <br>
          diff --git a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
          b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
          <br>
          index f5062d0c6333..b0a5baaebc43 100644
          <br>
          --- a/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
          <br>
          +++ b/drivers/gpu/drm/i915/gem/i915_gem_dmabuf.c
          <br>
          @@ -8,6 +8,7 @@
          <br>
            #include <linux/highmem.h>
          <br>
            #include <linux/dma-resv.h>
          <br>
            #include <linux/module.h>
          <br>
          +#include <drm/drm_cache.h>
          <br>
              #include <asm/smp.h>
          <br>
            @@ -250,16 +251,10 @@ static int
          i915_gem_object_get_pages_dmabuf(struct drm_i915_gem_object
          *obj)
          <br>
                 * DG1 is special here since it still snoops
          transactions even with
          <br>
                 * CACHE_NONE. This is not the case with other HAS_SNOOP
          platforms. We
          <br>
                 * might need to revisit this as we add new discrete
          platforms.
          <br>
          -     *
          <br>
          -     * XXX: Consider doing a vmap flush or something, where
          possible.
          <br>
          -     * Currently we just do a heavy handed
          wbinvd_on_all_cpus() here since
          <br>
          -     * the underlying sg_table might not even point to struct
          pages, so we
          <br>
          -     * can't just call drm_clflush_sg or similar, like we do
          elsewhere in
          <br>
          -     * the driver.
          <br>
                 */
          <br>
                if (i915_gem_object_can_bypass_llc(obj) ||
          <br>
                    (!HAS_LLC(i915) && !IS_DG1(i915)))
          <br>
          -        wbinvd_on_all_cpus();
          <br>
          +        drm_clflush_sg(pages);
          <br>
        </blockquote>
        <br>
        And as noticed before, drm_clfush_sg still can call
        wbinvd_on_all_cpus so are you just punting the issue somewhere
        else? How will it be solved there?
        <br>
      </blockquote>
      <br>
      I think in this case, drm_clflush_sg() can't be immediately used,
      because pages may not contain actual page pointers; might be just
      the dma address. It needs to be preceded with a dmabuf vmap.
      <br>
    </blockquote>
    <p>Could you elaborate more with using a dmabuf vmap?</p>
    <p>Doing a quick grep on drm_clflush_sg, were you thinking about
      something similar to the following? <br>
    </p>
    <div style="font-family: 'Liberation Mono', monospace; white-space: pre"><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">        </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">if (obj->cache_dirty) {</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                               </span><span style="color: undefined; background: #705050; font-weight: normal; font-style: normal; text-decoration: none"></span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                                 </span></div><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">WARN_ON_ONCE(IS_DGFX(i915));</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                  </span><span style="color: undefined; background: #705050; font-weight: normal; font-style: normal; text-decoration: none"></span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                              </span></div><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">obj->write_domain = 0;</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                         </span><span style="color: undefined; background: #705050; font-weight: normal; font-style: normal; text-decoration: none"></span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                                 </span></div><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">if (i915_gem_object_has_struct_page(obj))</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                      </span><span style="color: undefined; background: #705050; font-weight: normal; font-style: normal; text-decoration: none"></span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                                 </span></div><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                        </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">drm_clflush_sg(pages);</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                 </span><span style="color: undefined; background: #705050; font-weight: normal; font-style: normal; text-decoration: none"></span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                                 </span></div><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">obj->cache_dirty = false;</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                      </span><span style="color: undefined; background: #705050; font-weight: normal; font-style: normal; text-decoration: none"></span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">                                                 </span></div><div><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none"> </span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">        </span><span style="color: undefined; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">}</span><span style="color: #dcdccc; background: undefined; font-weight: normal; font-style: normal; text-decoration: none">        </span></div></div>
    <p><br>
    </p>
    <p>Thanks,</p>
    <p>Michael Cheng<br>
    </p>
    <blockquote type="cite" cite="mid:b986f2a7-c0d3-b145-dd45-54d25e10a8be@linux.intel.com">But
      otherwise this change, I figure, falls into the "prefer
      range-aware apis" category; If the CPU supports it, flush the
      range only, otherwise fall back to wbinvd().
      <br>
      <br>
      /Thomas
      <br>
      <br>
    </blockquote>
    <blockquote type="cite" cite="mid:b986f2a7-c0d3-b145-dd45-54d25e10a8be@linux.intel.com">
      <br>
      <blockquote type="cite">
        <br>
        Regards,
        <br>
        <br>
        Tvrtko
        <br>
        <br>
        <blockquote type="cite">        sg_page_sizes =
          i915_sg_dma_sizes(pages->sgl);
          <br>
                __i915_gem_object_set_pages(obj, pages, sg_page_sizes);
          <br>
        </blockquote>
      </blockquote>
    </blockquote>
  </body>
</html>