From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mfb02-md.ns.itscom.net ([175.177.155.110]:53440 "EHLO mfb02-md.ns.itscom.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750774AbcFQUz4 (ORCPT ); Fri, 17 Jun 2016 16:55:56 -0400 Received: from mail04-md.ns.itscom.net (mail04-md.ns.itscom.net [175.177.155.114]) by mfb02-md.ns.itscom.net (Postfix) with ESMTP id 35283170BB94 for ; Sat, 18 Jun 2016 05:50:33 +0900 (JST) From: "J. R. Okajima" To: viro@ZenIV.linux.org.uk, linux-fsdevel@vger.kernel.org Subject: Q. hlist_bl_add_head_rcu() in d_alloc_parallel() Date: Sat, 18 Jun 2016 05:50:30 +0900 Message-ID: <13136.1466196630@jrobl> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: I am afraid there may exist another violation of "no lookups on the same name in parallel" rule, but I am not sure. Roughly d_alloc_parallel() behaves like this. struct dentry *d_alloc_parallel() { new = d_alloc(parent, name); rcu_read_lock(); hlist_bl_lock(b); rcu_read_unlock(); hlist_bl_for_each_entry(dentry, node, b, d_u.d_in_lookup_hash) { if (!matched_dentry_found) continue; dget(dentry); hlist_bl_unlock(b); return dentry; } hlist_bl_add_head_rcu(&new->d_u.d_in_lookup_hash, b); hlist_bl_unlock(b); return new; } When two processes try opening a single existing file and enters d_alloc_parallel() at the same time, only one process wins and should succeeds hlist_bl_add_head_rcu(). The other process should find the dentry in d_u.d_in_lookup_hash and return 'dentry' (instead of 'new'). Am I right? My question is when will 'new' be added into d_u.d_in_lookup_hash? It should be between these two lines, I guess. rcu_read_unlock(); hlist_bl_for_each_entry(dentry, node, b, d_u.d_in_lookup_hash) { But can it surely happen? If 'new' is not added here because someone else is in rcu_read_lock region or other reason, then both processes will add the same named but different dentry? Is it better to change the lock/unlock-order like this? rcu_read_unlock(); rcu_barrier(); hlist_bl_lock(b); hlist_bl_for_each_entry(dentry, node, b, d_u.d_in_lookup_hash) { J. R. Okajima