Skip to content

Commit c68eee1

Browse files
committed
async: use ULLONG_MAX for infinity cookie value
Currently, next_cookie is used as the infinity value. In most cases, this should work fine but it theoretically could bring subtle behavior difference between async_synchronize_full() and async_synchronize_full_domain(). async_synchronize_full() keeps waiting until there's no registered async_entry left regardless of what next_cookie was when the function was called. It guarantees that the queue is completely drained at least once before returning. However, async_synchronize_full_domain() doesn't. It synchronizes upto next_cookie and if further async jobs are queued after the next_cookie value to synchronize is decided, they won't be waited for. For unrelated async jobs, the behavior difference doesn't matter; however, if async jobs which are related (nested or otherwise) to the executing ones are queued while sychronization is in progress, the resulting behavior difference could be problematic. This can be easily fixed by using ULLONG_MAX as the infinity value instead. Define ASYNC_COOKIE_MAX as ULLONG_MAX and use it as the infinity value for synchronization. This makes async_synchronize_full_domain() fully drain the domain at least once before returning, making its behavior match async_synchronize_full(). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Arjan van de Ven <arjan@linux.intel.com> Cc: Dan Williams <djbw@fb.com> Cc: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 8723d50 commit c68eee1

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

‎kernel/async.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ asynchronous and synchronous parts of the kernel.
6161

6262
static async_cookie_t next_cookie = 1;
6363

64-
#define MAX_WORK 32768
64+
#define MAX_WORK 32768
65+
#define ASYNC_COOKIE_MAX ULLONG_MAX /* infinity cookie */
6566

6667
static LIST_HEAD(async_pending);
6768
static ASYNC_DOMAIN(async_dfl_domain);
@@ -88,8 +89,8 @@ static atomic_t entry_count;
8889
*/
8990
static async_cookie_t __lowest_in_progress(struct async_domain *domain)
9091
{
91-
async_cookie_t first_running = next_cookie; /* infinity value */
92-
async_cookie_t first_pending = next_cookie; /* ditto */
92+
async_cookie_t first_running = ASYNC_COOKIE_MAX;
93+
async_cookie_t first_pending = ASYNC_COOKIE_MAX;
9394
struct async_entry *entry;
9495

9596
/*
@@ -269,7 +270,7 @@ void async_synchronize_full(void)
269270
domain = list_first_entry(&async_domains, typeof(*domain), node);
270271
spin_unlock_irq(&async_lock);
271272

272-
async_synchronize_cookie_domain(next_cookie, domain);
273+
async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, domain);
273274
} while (!list_empty(&async_domains));
274275
mutex_unlock(&async_register_mutex);
275276
}
@@ -305,7 +306,7 @@ EXPORT_SYMBOL_GPL(async_unregister_domain);
305306
*/
306307
void async_synchronize_full_domain(struct async_domain *domain)
307308
{
308-
async_synchronize_cookie_domain(next_cookie, domain);
309+
async_synchronize_cookie_domain(ASYNC_COOKIE_MAX, domain);
309310
}
310311
EXPORT_SYMBOL_GPL(async_synchronize_full_domain);
311312

0 commit comments

Comments
 (0)