Commit 8cfd33ca authored by Zizhi Wo's avatar Zizhi Wo Committed by Baokun Li
Browse files

fscache/cachefiles: add a memory barrier for waking and waiting

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/IB5UKT



--------------------------------

This patch modifies some functions, adds barriers in fscache/cachefiles to
both wake and wait processes that may be problematic due to out-of-order
memory.

Fixes: ef778e7a ("FS-Cache: Provide proper invalidation")
Fixes: da9803bc ("FS-Cache: Add interface to check consistency of a cached object")
Fixes: 94d30ae9 ("FS-Cache: Provide the ability to enable/disable cookies")
Fixes: b73608d715eb ("fscache: add a waiting mechanism when duplicate cookies are detected")
Signed-off-by: default avatarZizhi Wo <wozizhi@huawei.com>
Signed-off-by: default avatarBaokun Li <libaokun1@huawei.com>
parent e7213ad6
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -264,11 +264,9 @@ void cachefiles_mark_object_inactive(struct cachefiles_cache *cache,

	write_lock(&cache->active_lock);
	rb_erase(&object->active_node, &cache->active_nodes);
	clear_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags);
	clear_and_wake_up_bit(CACHEFILES_OBJECT_ACTIVE, &object->flags);
	write_unlock(&cache->active_lock);

	wake_up_bit(&object->flags, CACHEFILES_OBJECT_ACTIVE);

	/* This object can now be culled, so we need to let the daemon know
	 * that there is something it can remove if it needs to.
	 */
+7 −9
Original line number Diff line number Diff line
@@ -223,13 +223,13 @@ static int fscache_wait_on_cookie_collision(struct fscache_cookie *candidate)
{
	int ret;

	ret = wait_on_bit_timeout(&candidate->flags, FSCACHE_COOKIE_ACQUIRE_PENDING,
	ret = wait_on_bit_timeout_acquire(&candidate->flags, FSCACHE_COOKIE_ACQUIRE_PENDING,
					  TASK_INTERRUPTIBLE, 20 * HZ);
	if (ret == -EINTR)
		return ret;
	if (fscache_is_acquire_pending(candidate)) {
		pr_notice("Potential cookie collision!");
		return wait_on_bit(&candidate->flags, FSCACHE_COOKIE_ACQUIRE_PENDING,
		return wait_on_bit_acquire(&candidate->flags, FSCACHE_COOKIE_ACQUIRE_PENDING,
					   TASK_INTERRUPTIBLE);
	}
	return 0;
@@ -445,8 +445,7 @@ void __fscache_enable_cookie(struct fscache_cookie *cookie,
	}

out_unlock:
	clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
	wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
	clear_and_wake_up_bit(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
}
EXPORT_SYMBOL(__fscache_enable_cookie);

@@ -725,7 +724,7 @@ void __fscache_wait_on_invalidate(struct fscache_cookie *cookie)
{
	_enter("%p", cookie);

	wait_on_bit(&cookie->flags, FSCACHE_COOKIE_INVALIDATING,
	wait_on_bit_acquire(&cookie->flags, FSCACHE_COOKIE_INVALIDATING,
		    TASK_UNINTERRUPTIBLE);

	_leave("");
@@ -842,8 +841,7 @@ void __fscache_disable_cookie(struct fscache_cookie *cookie,
	}

out_unlock_enable:
	clear_bit_unlock(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
	wake_up_bit(&cookie->flags, FSCACHE_COOKIE_ENABLEMENT_LOCK);
	clear_and_wake_up_bit(FSCACHE_COOKIE_ENABLEMENT_LOCK, &cookie->flags);
	_leave("");
}
EXPORT_SYMBOL(__fscache_disable_cookie);
+4 −4
Original line number Diff line number Diff line
@@ -383,7 +383,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
	_debug(">>> WT");
	if (stat_op_waits)
		fscache_stat(stat_op_waits);
	if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
	if (wait_on_bit_acquire(&op->flags, FSCACHE_OP_WAITING,
				TASK_INTERRUPTIBLE) != 0) {
		trace_fscache_op(object->cookie, op, fscache_op_signal);
		ret = fscache_cancel_op(op, false);
@@ -392,7 +392,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,

		/* it's been removed from the pending queue by another party,
		 * so we should get to run shortly */
		wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
		wait_on_bit_acquire(&op->flags, FSCACHE_OP_WAITING,
				    TASK_UNINTERRUPTIBLE);
	}
	_debug("<<< GO");