[Devel] [PATCH rh7 3/3] tcache: make store put-put-get coherent

Vladimir Davydov vdavydov at parallels.com
Fri Jun 19 03:41:05 PDT 2015


A cleancache backend must be put-put-get coherent, meaning that if two
successive puts store AAA and BBB at the same offset, the following get
must never return AAA. Tcache conforms to this rule, but only if the
second put does not fail. If it does, the get will return the value
stored by the first put, resulting in user memory corruption. This
should not actually happen, because a file cache page is always removed
from its address space after put, so that double put is impossible.
However cleancache documentation states that this rule must hold, so
let's conform to it to be 100% secure.

Signed-off-by: Vladimir Davydov <vdavydov at parallels.com>
---
 mm/tcache.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/mm/tcache.c b/mm/tcache.c
index e83ad05da944..5d4320b42f5d 100644
--- a/mm/tcache.c
+++ b/mm/tcache.c
@@ -837,23 +837,27 @@ static void tcache_cleancache_put_page(int pool_id,
 	struct tcache_node *node;
 	struct page *cache_page;
 
-	if (!tcache_active)
-		return;
-
-	cache_page = tcache_alloc_page();
-	if (!cache_page)
-		return;
+	if (tcache_active)
+		cache_page = tcache_alloc_page();
+	else
+		cache_page = NULL;
 
-	copy_highpage(cache_page, page);
+	if (cache_page)
+		copy_highpage(cache_page, page);
 
-	node = tcache_get_node_and_pool(pool_id, &key, true);
+	node = tcache_get_node_and_pool(pool_id, &key, !!cache_page);
 	if (node) {
-		/* cleancache does not care about failures */
-		(void)tcache_attach_page(node, index, cache_page);
+		if (cache_page)
+			/* update the cache page */
+			(void)tcache_attach_page(node, index, cache_page);
+		else
+			/* invalidate the stale cache page */
+			cache_page = tcache_detach_page(node, index);
 		tcache_put_node_and_pool(node);
 	}
 
-	put_page(cache_page);
+	if (cache_page)
+		put_page(cache_page);
 }
 
 static int tcache_cleancache_get_page(int pool_id,
-- 
2.1.4




More information about the Devel mailing list