Skip to content

Commit 4722e2e

Browse files
nathanchanceAndi Shyti
authored andcommitted
drm/i915/gt: Fix second parameter type of pre-gen8 pte_encode callbacks
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: 9275277 ("drm/i915: use pat_index instead of cache_level") Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com> Reviewed-by: Fei Yang <fei.yang@intel.com> Signed-off-by: Andi 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
1 parent edad9ee commit 4722e2e

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

drivers/gpu/drm/i915/gt/intel_ggtt.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,16 +1015,16 @@ static int gen8_gmch_probe(struct i915_ggtt *ggtt)
10151015

10161016
/*
10171017
* For pre-gen8 platforms pat_index is the same as enum i915_cache_level,
1018-
* so these PTE encode functions are left with using cache_level.
1018+
* so the switch-case statements in these PTE encode functions are still valid.
10191019
* See translation table LEGACY_CACHELEVEL.
10201020
*/
10211021
static u64 snb_pte_encode(dma_addr_t addr,
1022-
enum i915_cache_level level,
1022+
unsigned int pat_index,
10231023
u32 flags)
10241024
{
10251025
gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
10261026

1027-
switch (level) {
1027+
switch (pat_index) {
10281028
case I915_CACHE_L3_LLC:
10291029
case I915_CACHE_LLC:
10301030
pte |= GEN6_PTE_CACHE_LLC;
@@ -1033,19 +1033,19 @@ static u64 snb_pte_encode(dma_addr_t addr,
10331033
pte |= GEN6_PTE_UNCACHED;
10341034
break;
10351035
default:
1036-
MISSING_CASE(level);
1036+
MISSING_CASE(pat_index);
10371037
}
10381038

10391039
return pte;
10401040
}
10411041

10421042
static u64 ivb_pte_encode(dma_addr_t addr,
1043-
enum i915_cache_level level,
1043+
unsigned int pat_index,
10441044
u32 flags)
10451045
{
10461046
gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
10471047

1048-
switch (level) {
1048+
switch (pat_index) {
10491049
case I915_CACHE_L3_LLC:
10501050
pte |= GEN7_PTE_CACHE_L3_LLC;
10511051
break;
@@ -1056,46 +1056,46 @@ static u64 ivb_pte_encode(dma_addr_t addr,
10561056
pte |= GEN6_PTE_UNCACHED;
10571057
break;
10581058
default:
1059-
MISSING_CASE(level);
1059+
MISSING_CASE(pat_index);
10601060
}
10611061

10621062
return pte;
10631063
}
10641064

10651065
static u64 byt_pte_encode(dma_addr_t addr,
1066-
enum i915_cache_level level,
1066+
unsigned int pat_index,
10671067
u32 flags)
10681068
{
10691069
gen6_pte_t pte = GEN6_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
10701070

10711071
if (!(flags & PTE_READ_ONLY))
10721072
pte |= BYT_PTE_WRITEABLE;
10731073

1074-
if (level != I915_CACHE_NONE)
1074+
if (pat_index != I915_CACHE_NONE)
10751075
pte |= BYT_PTE_SNOOPED_BY_CPU_CACHES;
10761076

10771077
return pte;
10781078
}
10791079

10801080
static u64 hsw_pte_encode(dma_addr_t addr,
1081-
enum i915_cache_level level,
1081+
unsigned int pat_index,
10821082
u32 flags)
10831083
{
10841084
gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
10851085

1086-
if (level != I915_CACHE_NONE)
1086+
if (pat_index != I915_CACHE_NONE)
10871087
pte |= HSW_WB_LLC_AGE3;
10881088

10891089
return pte;
10901090
}
10911091

10921092
static u64 iris_pte_encode(dma_addr_t addr,
1093-
enum i915_cache_level level,
1093+
unsigned int pat_index,
10941094
u32 flags)
10951095
{
10961096
gen6_pte_t pte = HSW_PTE_ADDR_ENCODE(addr) | GEN6_PTE_VALID;
10971097

1098-
switch (level) {
1098+
switch (pat_index) {
10991099
case I915_CACHE_NONE:
11001100
break;
11011101
case I915_CACHE_WT:

0 commit comments

Comments
 (0)