Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe48d9eb authored by Mitchel Humpherys's avatar Mitchel Humpherys
Browse files

ion: invalidate buffers before zero'ing



Currently, we invalidate the cache for buffers being zero'd *after* we
zero them. However, this is racey since a dirty cache line from an
earlier mapping could be written out to memory between the zero'ing and
the invalidation. Fix this by invalidating the cache *before* zero'ing
the buffer.

Before this change, I was seeing corruption with:

    $ cat <<EOF | ./memory_prof -e -i -
    simple_alloc,1,ION_SYSTEM_HEAP_ID,ION_FLAG_CACHED,0x100000,1MB
    simple_basic_sanity,1
    simple_profile,1
    simple_free,1
    EOF

After this change, no corruption.

Change-Id: I1f2603604efc9be4ebf9112b06728e0aeca60ea0
Signed-off-by: default avatarMitchel Humpherys <mitchelh@codeaurora.org>
parent 4db175e5
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -146,9 +146,11 @@ int ion_heap_pages_zero(struct page **pages, int num_pages)
		if (!ptr)
			return -ENOMEM;

		memset(ptr, 0, npages_to_vmap * PAGE_SIZE);
		/*
		 * invalidate the cache to pick up the zeroing
		 * We have to invalidate the cache here because there
		 * might be dirty lines to these physical pages (which
		 * we don't care about) that could get written out at
		 * any moment.
		 */
		for (k = 0; k < npages_to_vmap; k++) {
			void *p = kmap_atomic(pages[i + k]);
@@ -156,6 +158,7 @@ int ion_heap_pages_zero(struct page **pages, int num_pages)
			dmac_inv_range(p, p + PAGE_SIZE);
			kunmap_atomic(p);
		}
		memset(ptr, 0, npages_to_vmap * PAGE_SIZE);
		vunmap(ptr);
	}