1. 02 Jun, 2023 2 commits
    • Nathan Chancellor's avatar
      drm/i915/gt: Fix parameter in gmch_ggtt_insert_{entries, page}() · 1baeef6c
      Nathan Chancellor authored
      When building with clang's -Wincompatible-function-pointer-types-strict,
      the following warnings occur:
      
        drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:102:23: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, dma_addr_t, u64, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, unsigned int, unsigned long long, unsigned int, unsigned int)') from 'void (struct i915_address_space *, dma_addr_t, u64, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, unsigned int, unsigned long long, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
                ggtt->vm.insert_page = gmch_ggtt_insert_page;
                                     ^ ~~~~~~~~~~~~~~~~~~~~~
        drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:103:26: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, unsigned int)') from 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, unsigned int)') [-Werror, -Wincompatible-function-pointer-types-strict]
                ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
                                        ^ ~~~~~~~~~~~~~~~~~~~~~~~~
        2 errors generated.
      
      The warning is pointing out that while 'enum i915_cache_level' and
      'unsigned int' are ABI compatible, these indirect calls will fail
      clang's kernel Control Flow Integrity (kCFI) checks, as the callback's
      signature does not exactly match the prototype's signature.
      
      To fix this, replace the cache_level parameter with pat_index, as was
      done in other places within i915 where there is no difference between
      cache_level and pat_index on certain generations.
      
      Fixes: 9275277d ("drm/i915: use pat_index instead of cache_level")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Reviewed-by: default avatarFei Yang <fei.yang@intel.com>
      Signed-off-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20230530-i915-gt-cache_level-wincompatible-function-pointer-types-strict-v1-2-54501d598229@kernel.org
      1baeef6c
    • Nathan Chancellor's avatar
      drm/i915/gt: Fix second parameter type of pre-gen8 pte_encode callbacks · 4722e2eb
      Nathan Chancellor authored
      When booting a kernel compiled with CONFIG_CFI_CLANG (kCFI), there is a
      CFI failure in ggtt_probe_common() when trying to call hsw_pte_encode()
      via an indirect call:
      
        [    5.030027] CFI failure at ggtt_probe_common+0xd1/0x130 [i915] (target: hsw_pte_encode+0x0/0x30 [i915]; expected type: 0xf5c1d0fc)
      
      With kCFI, indirect calls are validated against their expected type
      versus actual type and failures occur when the two types do not match.
      
      clang's -Wincompatible-function-pointer-types-strict can catch this at
      compile time but it is not enabled for the kernel yet:
      
        drivers/gpu/drm/i915/gt/intel_ggtt.c:1155:23: error: incompatible function pointer types assigning to 'u64 (*)(dma_addr_t, unsigned int, u32)' (aka 'unsigned long long (*)(unsigned int, unsigned int, unsigned int)') from 'u64 (dma_addr_t,
        enum i915_cache_level, u32)' (aka 'unsigned long long (unsigned int, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
                        ggtt->vm.pte_encode = iris_pte_encode;
                                            ^ ~~~~~~~~~~~~~~~
        drivers/gpu/drm/i915/gt/intel_ggtt.c:1157:23: error: incompatible function pointer types assigning to 'u64 (*)(dma_addr_t, unsigned int, u32)' (aka 'unsigned long long (*)(unsigned int, unsigned int, unsigned int)') from 'u64 (dma_addr_t,
        enum i915_cache_level, u32)' (aka 'unsigned long long (unsigned int, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
                        ggtt->vm.pte_encode = hsw_pte_encode;
                                            ^ ~~~~~~~~~~~~~~
        drivers/gpu/drm/i915/gt/intel_ggtt.c:1159:23: error: incompatible function pointer types assigning to 'u64 (*)(dma_addr_t, unsigned int, u32)' (aka 'unsigned long long (*)(unsigned int, unsigned int, unsigned int)') from 'u64 (dma_addr_t,
        enum i915_cache_level, u32)' (aka 'unsigned long long (unsigned int, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
                        ggtt->vm.pte_encode = byt_pte_encode;
                                            ^ ~~~~~~~~~~~~~~
        drivers/gpu/drm/i915/gt/intel_ggtt.c:1161:23: error: incompatible function pointer types assigning to 'u64 (*)(dma_addr_t, unsigned int, u32)' (aka 'unsigned long long (*)(unsigned int, unsigned int, unsigned int)') from 'u64 (dma_addr_t,
        enum i915_cache_level, u32)' (aka 'unsigned long long (unsigned int, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
                        ggtt->vm.pte_encode = ivb_pte_encode;
                                            ^ ~~~~~~~~~~~~~~
        drivers/gpu/drm/i915/gt/intel_ggtt.c:1163:23: error: incompatible function pointer types assigning to 'u64 (*)(dma_addr_t, unsigned int, u32)' (aka 'unsigned long long (*)(unsigned int, unsigned int, unsigned int)') from 'u64 (dma_addr_t,
        enum i915_cache_level, u32)' (aka 'unsigned long long (unsigned int, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
                        ggtt->vm.pte_encode = snb_pte_encode;
                                            ^ ~~~~~~~~~~~~~~
        5 errors generated.
      
      In this case, the pre-gen8 pte_encode functions have a second parameter
      type of 'enum i915_cache_level' whereas the function pointer prototype
      in 'struct i915_address_space' expects a second parameter type of
      'unsigned int'.
      
      Update the second parameter of the callbacks and the comment above them
      noting that these statements are still valid, which matches other
      functions and files, to clear up the kCFI failures at run time.
      
      Fixes: 9275277d ("drm/i915: use pat_index instead of cache_level")
      Signed-off-by: default avatarNathan Chancellor <nathan@kernel.org>
      Reviewed-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Reviewed-by: default avatarFei Yang <fei.yang@intel.com>
      Signed-off-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20230530-i915-gt-cache_level-wincompatible-function-pointer-types-strict-v1-1-54501d598229@kernel.org
      4722e2eb
  2. 01 Jun, 2023 1 commit
  3. 31 May, 2023 4 commits
  4. 30 May, 2023 4 commits
  5. 26 May, 2023 1 commit
  6. 23 May, 2023 1 commit
  7. 22 May, 2023 7 commits
  8. 19 May, 2023 1 commit
  9. 18 May, 2023 3 commits
  10. 17 May, 2023 1 commit
  11. 16 May, 2023 2 commits
  12. 15 May, 2023 1 commit
  13. 12 May, 2023 10 commits
  14. 11 May, 2023 2 commits
    • Fei Yang's avatar
      drm/i915: use pat_index instead of cache_level · 9275277d
      Fei Yang authored
      Currently the KMD is using enum i915_cache_level to set caching policy for
      buffer objects. This is flaky because the PAT index which really controls
      the caching behavior in PTE has far more levels than what's defined in the
      enum. In addition, the PAT index is platform dependent, having to translate
      between i915_cache_level and PAT index is not reliable, and makes the code
      more complicated.
      
      From UMD's perspective there is also a necessity to set caching policy for
      performance fine tuning. It's much easier for the UMD to directly use PAT
      index because the behavior of each PAT index is clearly defined in Bspec.
      Having the abstracted i915_cache_level sitting in between would only cause
      more ambiguity. PAT is expected to work much like MOCS already works today,
      and by design userspace is expected to select the index that exactly
      matches the desired behavior described in the hardware specification.
      
      For these reasons this patch replaces i915_cache_level with PAT index. Also
      note, the cache_level is not completely removed yet, because the KMD still
      has the need of creating buffer objects with simple cache settings such as
      cached, uncached, or writethrough. For kernel objects, cache_level is used
      for simplicity and backward compatibility. For Pre-gen12 platforms PAT can
      have 1:1 mapping to i915_cache_level, so these two are interchangeable. see
      the use of LEGACY_CACHELEVEL.
      
      One consequence of this change is that gen8_pte_encode is no longer working
      for gen12 platforms due to the fact that gen12 platforms has different PAT
      definitions. In the meantime the mtl_pte_encode introduced specfically for
      MTL becomes generic for all gen12 platforms. This patch renames the MTL
      PTE encode function into gen12_pte_encode and apply it to all gen12. Even
      though this change looks unrelated, but separating them would temporarily
      break gen12 PTE encoding, thus squash them in one patch.
      
      Special note: this patch changes the way caching behavior is controlled in
      the sense that some objects are left to be managed by userspace. For such
      objects we need to be careful not to change the userspace settings.There
      are kerneldoc and comments added around obj->cache_coherent, cache_dirty,
      and how to bypass the checkings by i915_gem_object_has_cache_level. For
      full understanding, these changes need to be looked at together with the
      two follow-up patches, one disables the {set|get}_caching ioctl's and the
      other adds set_pat extension to the GEM_CREATE uAPI.
      
      Bspec: 63019
      
      Cc: Chris Wilson <chris.p.wilson@linux.intel.com>
      Signed-off-by: default avatarFei Yang <fei.yang@intel.com>
      Reviewed-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Reviewed-by: default avatarMatt Roper <matthew.d.roper@intel.com>
      Signed-off-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20230509165200.1740-3-fei.yang@intel.com
      9275277d
    • Fei Yang's avatar
      drm/i915: preparation for using PAT index · 5e352e32
      Fei Yang authored
      This patch is a preparation for replacing enum i915_cache_level with PAT
      index. Caching policy for buffer objects is set through the PAT index in
      PTE, the old i915_cache_level is not sufficient to represent all caching
      modes supported by the hardware.
      
      Preparing the transition by adding some platform dependent data structures
      and helper functions to translate the cache_level to pat_index.
      
      cachelevel_to_pat: a platform dependent array mapping cache_level to
                         pat_index.
      
      max_pat_index: the maximum PAT index recommended in hardware specification
                     Needed for validating the PAT index passed in from user
                     space.
      
      i915_gem_get_pat_index: function to convert cache_level to PAT index.
      
      obj_to_i915(obj): macro moved to header file for wider usage.
      
      I915_MAX_CACHE_LEVEL: upper bound of i915_cache_level for the
                            convenience of coding.
      
      Cc: Chris Wilson <chris.p.wilson@linux.intel.com>
      Cc: Matt Roper <matthew.d.roper@intel.com>
      Signed-off-by: default avatarFei Yang <fei.yang@intel.com>
      Reviewed-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Reviewed-by: default avatarAndrzej Hajda <andrzej.hajda@intel.com>
      Signed-off-by: default avatarAndi Shyti <andi.shyti@linux.intel.com>
      Link: https://patchwork.freedesktop.org/patch/msgid/20230509165200.1740-2-fei.yang@intel.com
      5e352e32