Skip to contentSkip to conversation

i915: fix invalid opcode exception on cpus without clflush

PATCH In review Kyle McMartin 3 participants 4 messages Jan 17, 2008 – Jan 18, 2008 Char and misc drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i915: fix invalid opcode exception on cpus without clflush

i915_flush_ttm was unconditionally executing a clflush instruction to (obviously) flush the cache. Instead, check if the cpu supports clflush, and if not, fall back to calling wbinvd to flush the entire cache.

drivers/char/drm/i915_buffer.c +11 -0
@@ -286,7 +286,18 @@ void i915_flush_ttm(struct drm_ttm *ttm)
 		return;
 
 	DRM_MEMORYBARRIER();
+
+#ifdef CONFIG_X86_32
+	/* Hopefully nobody has built an x86-64 processor without clflush */
+	if (!cpu_has_clflush) {
+		wbinvd();
+		DRM_MEMORYBARRIER();
+		return;
+	}
+#endif
+
 	for (i = ttm->num_pages - 1; i >= 0; i--)
 		drm_cache_flush_page(drm_ttm_get_page(ttm, i));
+
 	DRM_MEMORYBARRIER();
 }
#1 lore raw
Quoted 18 lines · Kyle McMartin

i915_flush_ttm was unconditionally executing a clflush instruction to (obviously) flush the cache. Instead, check if the cpu supports clflush, and if not, fall back to calling wbinvd to flush the entire cache.

drivers/char/drm/i915_buffer.c +5 -0
@@ -286,7 +286,18 @@ void i915_flush_ttm(struct drm_ttm *ttm)
 		return;
 
 	DRM_MEMORYBARRIER();
+
+#ifdef CONFIG_X86_32
+	/* Hopefully nobody has built an x86-64 processor without clflush */
+	if (!cpu_has_clflush) {
+		wbinvd();

drivers/char/drm/i915_buffer.c void i915_flush_ttm(struct drm_ttm *ttm) · line 303

Quoted 10 lines
drivers/char/drm/i915_buffer.c +6 -0
+		DRM_MEMORYBARRIER();
+		return;
+	}
+#endif
+
 	for (i = ttm->num_pages - 1; i >= 0; i--)
 		drm_cache_flush_page(drm_ttm_get_page(ttm, i));
+
 	DRM_MEMORYBARRIER();
 }

The #ifdef is bogus. If it's required, it should go into asm-x86/required_features.h and then cpu_has_clflush is static; otherwise it's just plain wrong.

-hpa

#2 lore raw
Quoted 25 lines · H. Peter Anvin
Quoted 24 lines · Kyle McMartin

i915_flush_ttm was unconditionally executing a clflush instruction to (obviously) flush the cache. Instead, check if the cpu supports clflush, and if not, fall back to calling wbinvd to flush the entire cache.

drivers/char/drm/i915_buffer.c +10 -0
@@ -286,7 +286,18 @@ void i915_flush_ttm(struct drm_ttm *ttm)
 		return;
 
 	DRM_MEMORYBARRIER();
+
+#ifdef CONFIG_X86_32
+	/* Hopefully nobody has built an x86-64 processor without clflush */
+	if (!cpu_has_clflush) {
+		wbinvd();
+		DRM_MEMORYBARRIER();
+		return;
+	}
+#endif
+
 	for (i = ttm->num_pages - 1; i >= 0; i--)
Quoted 8 lines

drivers/char/drm/i915_buffer.c void i915_flush_ttm(struct drm_ttm *ttm) · line 303

Quoted 4 lines
drivers/char/drm/i915_buffer.c +1 -0
 		drm_cache_flush_page(drm_ttm_get_page(ttm, i));
+
 	DRM_MEMORYBARRIER();
 }

The #ifdef is bogus. If it's required, it should go into asm-x86/required_features.h and then cpu_has_clflush is static; otherwise it's just plain wrong.

I think Andi's CPA patches have some changes regarding wbinvd and clflush handling, perhaps you can leverage some of his work?

Harvey

#3 lore raw
In reply to H. Peter Anvin
Quoted 4 lines · H. Peter Anvin

The #ifdef is bogus. If it's required, it should go into asm-x86/required_features.h and then cpu_has_clflush is static; otherwise it's just plain wrong.

I have no objection to making cpu_has_clflush constant on x86_64. The point was to get rid of a needless test & branch on 64-bit, and making it constant will have the same effect.

cheers, Kyle