Skip to content

Commit 40b3990

Browse files
trueptolemytursulin
authored andcommitted
drm/i915: Use kmap_local_page() in gem/selftests/i915_gem_coherency.c
The use of kmap_atomic() is being deprecated in favor of kmap_local_page()[1], and this patch converts the call from kmap_atomic() to kmap_local_page(). The main difference between atomic and local mappings is that local mappings doesn't disable page faults or preemption (the preemption is disabled for !PREEMPT_RT case, otherwise it only disables migration).. With kmap_local_page(), we can avoid the often unwanted side effect of unnecessary page faults or preemption disables. In drm/i915/gem/selftests/i915_gem_coherency.c, functions cpu_set() and cpu_get() mainly uses mapping to flush cache and assign the value. There're 2 reasons why cpu_set() and cpu_get() don't need to disable pagefaults and preemption for mapping: 1. The flush operation is safe. cpu_set() and cpu_get() call drm_clflush_virt_range() to use CLFLUSHOPT or WBINVD to flush. Since CLFLUSHOPT is global on x86 and WBINVD is called on each cpu in drm_clflush_virt_range(), the flush operation is global. 2. Any context switch caused by preemption or page faults (page fault may cause sleep) doesn't affect the validity of local mapping. Therefore, cpu_set() and cpu_get() are functions where the use of kmap_local_page() in place of kmap_atomic() is correctly suited. Convert the calls of kmap_atomic() / kunmap_atomic() to kmap_local_page() / kunmap_local(). [1]: https://lore.kernel.org/all/20220813220034.806698-1-ira.weiny@intel.com Suggested-by: Dave Hansen <dave.hansen@intel.com> Suggested-by: Ira Weiny <ira.weiny@intel.com> Suggested-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Fabio M. De Francesco <fmdefrancesco@gmail.com> Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20231203132947.2328805-6-zhao1.liu@linux.intel.com
1 parent 1fcb967 commit 40b3990

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

drivers/gpu/drm/i915/gem/selftests/i915_gem_coherency.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v)
2424
{
2525
unsigned int needs_clflush;
2626
struct page *page;
27-
void *map;
2827
u32 *cpu;
2928
int err;
3029

@@ -34,8 +33,7 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v)
3433
goto out;
3534

3635
page = i915_gem_object_get_page(ctx->obj, offset >> PAGE_SHIFT);
37-
map = kmap_atomic(page);
38-
cpu = map + offset_in_page(offset);
36+
cpu = kmap_local_page(page) + offset_in_page(offset);
3937

4038
if (needs_clflush & CLFLUSH_BEFORE)
4139
drm_clflush_virt_range(cpu, sizeof(*cpu));
@@ -45,7 +43,7 @@ static int cpu_set(struct context *ctx, unsigned long offset, u32 v)
4543
if (needs_clflush & CLFLUSH_AFTER)
4644
drm_clflush_virt_range(cpu, sizeof(*cpu));
4745

48-
kunmap_atomic(map);
46+
kunmap_local(cpu);
4947
i915_gem_object_finish_access(ctx->obj);
5048

5149
out:
@@ -57,7 +55,6 @@ static int cpu_get(struct context *ctx, unsigned long offset, u32 *v)
5755
{
5856
unsigned int needs_clflush;
5957
struct page *page;
60-
void *map;
6158
u32 *cpu;
6259
int err;
6360

@@ -67,15 +64,14 @@ static int cpu_get(struct context *ctx, unsigned long offset, u32 *v)
6764
goto out;
6865

6966
page = i915_gem_object_get_page(ctx->obj, offset >> PAGE_SHIFT);
70-
map = kmap_atomic(page);
71-
cpu = map + offset_in_page(offset);
67+
cpu = kmap_local_page(page) + offset_in_page(offset);
7268

7369
if (needs_clflush & CLFLUSH_BEFORE)
7470
drm_clflush_virt_range(cpu, sizeof(*cpu));
7571

7672
*v = *cpu;
7773

78-
kunmap_atomic(map);
74+
kunmap_local(cpu);
7975
i915_gem_object_finish_access(ctx->obj);
8076

8177
out:

0 commit comments

Comments
 (0)