All of lore.kernel.org
 help / color / mirror / Atom feed
* [Intel-gfx] [bug report] drm/i915/migrate: Evict and restore the flatccs capable lmem obj
@ 2022-05-05 10:31 Dan Carpenter
  0 siblings, 0 replies; only message in thread
From: Dan Carpenter @ 2022-05-05 10:31 UTC (permalink / raw)
  To: ramalingam.c; +Cc: intel-gfx

Hello Ramalingam C,

The patch da0595ae91da: "drm/i915/migrate: Evict and restore the
flatccs capable lmem obj" from Apr 5, 2022, leads to the following
Smatch static checker warning:

drivers/gpu/drm/i915/gt/intel_migrate.c:832 intel_context_migrate_copy() error: uninitialized symbol 'ccs_cache_level'.
drivers/gpu/drm/i915/gt/intel_migrate.c:833 intel_context_migrate_copy() error: uninitialized symbol 'ccs_is_src'.

drivers/gpu/drm/i915/gt/intel_migrate.c
    695 int
    696 intel_context_migrate_copy(struct intel_context *ce,
    697                            const struct i915_deps *deps,
    698                            struct scatterlist *src,
    699                            enum i915_cache_level src_cache_level,
    700                            bool src_is_lmem,
    701                            struct scatterlist *dst,
    702                            enum i915_cache_level dst_cache_level,
    703                            bool dst_is_lmem,
    704                            struct i915_request **out)
    705 {
    706         struct sgt_dma it_src = sg_sgt(src), it_dst = sg_sgt(dst), it_ccs;
    707         struct drm_i915_private *i915 = ce->engine->i915;
    708         u32 ccs_bytes_to_cpy = 0, bytes_to_cpy;
    709         enum i915_cache_level ccs_cache_level;
    710         int src_sz, dst_sz, ccs_sz;
    711         u32 src_offset, dst_offset;
    712         u8 src_access, dst_access;
    713         struct i915_request *rq;
    714         bool ccs_is_src;
    715         int err;
    716 
    717         GEM_BUG_ON(ce->vm != ce->engine->gt->migrate.context->vm);
    718         GEM_BUG_ON(IS_DGFX(ce->engine->i915) && (!src_is_lmem && !dst_is_lmem));
    719         *out = NULL;
    720 
    721         GEM_BUG_ON(ce->ring->size < SZ_64K);
    722 
    723         src_sz = scatter_list_length(src);
    724         bytes_to_cpy = src_sz;
    725 
    726         if (HAS_FLAT_CCS(i915) && src_is_lmem ^ dst_is_lmem) {
    727                 src_access = !src_is_lmem && dst_is_lmem;
    728                 dst_access = !src_access;
    729 
    730                 dst_sz = scatter_list_length(dst);
    731                 if (src_is_lmem) {
    732                         it_ccs = it_dst;
    733                         ccs_cache_level = dst_cache_level;
    734                         ccs_is_src = false;
    735                 } else if (dst_is_lmem) {
    736                         bytes_to_cpy = dst_sz;
    737                         it_ccs = it_src;
    738                         ccs_cache_level = src_cache_level;
                                ^^^^^^^^^^^^^^^
    739                         ccs_is_src = true;
    740                 }

There is no else statement.  Presumably either src_is_lmem or dst_is_lmem
is always going to be true but apparently Smatch can't figure that out.

    741 
    742                 /*
    743                  * When there is a eviction of ccs needed smem will have the
    744                  * extra pages for the ccs data
    745                  *
    746                  * TO-DO: Want to move the size mismatch check to a WARN_ON,
    747                  * but still we have some requests of smem->lmem with same size.
    748                  * Need to fix it.
    749                  */
    750                 ccs_bytes_to_cpy = src_sz != dst_sz ? GET_CCS_BYTES(i915, bytes_to_cpy) : 0;
    751                 if (ccs_bytes_to_cpy)
    752                         get_ccs_sg_sgt(&it_ccs, bytes_to_cpy);
    753         }
    754 
    755         src_offset = 0;
    756         dst_offset = CHUNK_SZ;
    757         if (HAS_64K_PAGES(ce->engine->i915)) {
    758                 src_offset = 0;
    759                 dst_offset = 0;
    760                 if (src_is_lmem)
    761                         src_offset = CHUNK_SZ;
    762                 if (dst_is_lmem)
    763                         dst_offset = 2 * CHUNK_SZ;
    764         }
    765 
    766         do {
    767                 int len;
    768 
    769                 rq = i915_request_create(ce);
    770                 if (IS_ERR(rq)) {
    771                         err = PTR_ERR(rq);
    772                         goto out_ce;
    773                 }
    774 
    775                 if (deps) {
    776                         err = i915_request_await_deps(rq, deps);
    777                         if (err)
    778                                 goto out_rq;
    779 
    780                         if (rq->engine->emit_init_breadcrumb) {
    781                                 err = rq->engine->emit_init_breadcrumb(rq);
    782                                 if (err)
    783                                         goto out_rq;
    784                         }
    785 
    786                         deps = NULL;
    787                 }
    788 
    789                 /* The PTE updates + copy must not be interrupted. */
    790                 err = emit_no_arbitration(rq);
    791                 if (err)
    792                         goto out_rq;
    793 
    794                 calculate_chunk_sz(i915, src_is_lmem, &src_sz, &ccs_sz,
    795                                    bytes_to_cpy, ccs_bytes_to_cpy);
    796 
    797                 len = emit_pte(rq, &it_src, src_cache_level, src_is_lmem,
    798                                src_offset, src_sz);
    799                 if (!len) {
    800                         err = -EINVAL;
    801                         goto out_rq;
    802                 }
    803                 if (len < 0) {
    804                         err = len;
    805                         goto out_rq;
    806                 }
    807 
    808                 err = emit_pte(rq, &it_dst, dst_cache_level, dst_is_lmem,
    809                                dst_offset, len);
    810                 if (err < 0)
    811                         goto out_rq;
    812                 if (err < len) {
    813                         err = -EINVAL;
    814                         goto out_rq;
    815                 }
    816 
    817                 err = rq->engine->emit_flush(rq, EMIT_INVALIDATE);
    818                 if (err)
    819                         goto out_rq;
    820 
    821                 err = emit_copy(rq, dst_offset,        src_offset, len);
    822                 if (err)
    823                         goto out_rq;
    824 
    825                 bytes_to_cpy -= len;
    826 
    827                 if (ccs_bytes_to_cpy) {
    828                         err = rq->engine->emit_flush(rq, EMIT_INVALIDATE);
    829                         if (err)
    830                                 goto out_rq;
    831 
--> 832                         err = emit_pte(rq, &it_ccs, ccs_cache_level, false,
                                                            ^^^^^^^^^^^^^^^

    833                                        ccs_is_src ? src_offset : dst_offset,
    834                                        ccs_sz);
    835 
    836                         err = rq->engine->emit_flush(rq, EMIT_INVALIDATE);
    837                         if (err)
    838                                 goto out_rq;
    839 
    840                         /*
    841                          * Using max of src_sz and dst_sz, as we need to
    842                          * pass the lmem size corresponding to the ccs
    843                          * blocks we need to handle.
    844                          */
    845                         ccs_sz = max_t(int, ccs_is_src ? ccs_sz : src_sz,
    846                                        ccs_is_src ? dst_sz : ccs_sz);
    847 
    848                         err = emit_copy_ccs(rq, dst_offset, dst_access,
    849                                             src_offset, src_access, ccs_sz);
    850                         if (err)
    851                                 goto out_rq;
    852 
    853                         err = rq->engine->emit_flush(rq, EMIT_INVALIDATE);
    854                         if (err)
    855                                 goto out_rq;
    856 
    857                         /* Converting back to ccs bytes */
    858                         ccs_sz = GET_CCS_BYTES(rq->engine->i915, ccs_sz);
    859                         ccs_bytes_to_cpy -= ccs_sz;
    860                 }
    861 
    862                 /* Arbitration is re-enabled between requests. */
    863 out_rq:
    864                 if (*out)
    865                         i915_request_put(*out);
    866                 *out = i915_request_get(rq);
    867                 i915_request_add(rq);
    868 
    869                 if (err)
    870                         break;
    871 
    872                 if (!bytes_to_cpy && !ccs_bytes_to_cpy) {
    873                         if (src_is_lmem)
    874                                 WARN_ON(it_src.sg && sg_dma_len(it_src.sg));
    875                         else
    876                                 WARN_ON(it_dst.sg && sg_dma_len(it_dst.sg));
    877                         break;
    878                 }
    879 
    880                 if (WARN_ON(!it_src.sg || !sg_dma_len(it_src.sg) ||
    881                             !it_dst.sg || !sg_dma_len(it_dst.sg) ||
    882                             (ccs_bytes_to_cpy && (!it_ccs.sg ||
    883                                                   !sg_dma_len(it_ccs.sg))))) {
    884                         err = -EINVAL;
    885                         break;
    886                 }
    887 
    888                 cond_resched();
    889         } while (1);
    890 
    891 out_ce:
    892         return err;
    893 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-05 10:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-05 10:31 [Intel-gfx] [bug report] drm/i915/migrate: Evict and restore the flatccs capable lmem obj Dan Carpenter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.