Flush the modified directory entry before unmapping it. The old order
uses a kmap_atomic pointer outside its mapping lifetime, which DMA32
direct mappings can mask. Use kmap_local_page under the existing spinlock.

Also calculate the CLFLUSH iteration count only on the path that uses it,
avoiding division by an uninitialized cache-line size when CLFLUSH
is absent.

Signed-off-by: Gabriel Gama <[email protected]>

---
 drivers/gpu/drm/gma500/mmu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/gma500/mmu.c b/drivers/gpu/drm/gma500/mmu.c
index 4fbc22a59..34ae0f125 100644
--- a/drivers/gpu/drm/gma500/mmu.c
+++ b/drivers/gpu/drm/gma500/mmu.c
@@ -265,7 +265,7 @@ static struct psb_mmu_pt *psb_mmu_alloc_pt(struct 
psb_mmu_pd *pd)
        struct psb_mmu_pt *pt = kmalloc_obj(*pt);
        void *v;
        uint32_t clflush_add = pd->driver->clflush_add >> PAGE_SHIFT;
-       uint32_t clflush_count = PAGE_SIZE / clflush_add;
+       u32 clflush_count;
        spinlock_t *lock = &pd->driver->lock;
        uint8_t *clf;
        uint32_t *ptes;
@@ -289,6 +289,7 @@ static struct psb_mmu_pt *psb_mmu_alloc_pt(struct 
psb_mmu_pd *pd)
                *ptes++ = pd->invalid_pte;
 
        if (pd->driver->has_clflush && pd->hw_context != -1) {
+               clflush_count = PAGE_SIZE / clflush_add;
                mb();
                for (i = 0; i < clflush_count; ++i) {
                        psb_clflush(clf);
@@ -331,16 +332,15 @@ static struct psb_mmu_pt 
*psb_mmu_pt_alloc_map_lock(struct psb_mmu_pd *pd,
                        continue;
                }
 
-               v = kmap_atomic(pd->p);
+               v = kmap_local_page(pd->p);
                pd->tables[index] = pt;
                v[index] = (page_to_pfn(pt->p) << 12) | pd->pd_mask;
                pt->index = index;
-               kunmap_atomic((void *) v);
-
                if (pd->hw_context != -1) {
                        psb_mmu_clflush(pd->driver, (void *)&v[index]);
                        atomic_set(&pd->driver->needs_tlbflush, 1);
                }
+               kunmap_local(v);
        }
        pt->v = kmap_atomic(pt->p);
        return pt;

Reply via email to