Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp244277ybl; Thu, 23 Jan 2020 22:50:13 -0800 (PST) X-Google-Smtp-Source: APXvYqwlNdftPImogvwWOIy4K5ZiEmf9tRSH/8bMb8fXDWRSfMOMOX8PLAr+PV1/a9TrrtN3OaSR X-Received: by 2002:a54:4117:: with SMTP id l23mr1070820oic.140.1579848613591; Thu, 23 Jan 2020 22:50:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579848613; cv=none; d=google.com; s=arc-20160816; b=sg1mveGMjhN+upyfH1whIcHnszc6ZaXsvnApu2yTtMjAJVtCi6Ao80L7OEKP5lG9yL gCfcnsS2S5McNVnGd3ea1/tEjnxS4geLo536kNRTEQqXTY3tU0FKlNklGVDzWWK0PJ2r CRsMvH8lUtYqU2MZtVDwrwVmkMd6nMWs6bmI8p21DEZHCshIYco2+fuVaDkLeWx5dNKF V2VMejKoTnN0h8v0Px3AoNPXC0cVnsL8vjp0fwvwa+c5jwRcTAi2o93HcWSZLHmOwZfe n3C/3hVQNVWp2UiO34SfMvHZGZI4IfK3pGNsNEhF/BEkfPeym0y9dTBscgcD95mV85Ft wuqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=rzOCOg+HRigNJBDCSh5M7t66n+4i+nmXOEYhY7A53/0=; b=VUCgiDdbym8ItxBPVylCThWsKlZ7PdGizzuB+0syUdmpfKYR2PuJfkCPfbqnb1usg2 +L9/O1Zh2WQoUlvwuR/8lSqw2OrmJcE72mgG/Dq8QjX6U7e7gaIZMjGqBF2J6aaDqVUE 6VLY1FJALaHfYCAO3lVXHesXDUNk/Jv2CxJ7ExlLj931EYKY6uPCKgNU8406LTQqq//F HsDvVAbfH+1JUvXhtj5Zrxb9//0jrDRLJDnb3vSlYAGGJF7RQNzYwe3FGRJImjqWRhD7 QvUgT2pgCpze52wgikpdiNPMHL2r2lJua8dJqIaNOytiLcdCf583I1cUIm2Z/q5LiXpJ cSVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=plqGOK85; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r82si564578oie.116.2020.01.23.22.49.49; Thu, 23 Jan 2020 22:50:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@aol.com header.s=a2048 header.b=plqGOK85; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=aol.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729942AbgAXGPm (ORCPT + 99 others); Fri, 24 Jan 2020 01:15:42 -0500 Received: from sonic304-23.consmr.mail.gq1.yahoo.com ([98.137.68.204]:33635 "EHLO sonic304-23.consmr.mail.gq1.yahoo.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725817AbgAXGPl (ORCPT ); Fri, 24 Jan 2020 01:15:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aol.com; s=a2048; t=1579846539; bh=rzOCOg+HRigNJBDCSh5M7t66n+4i+nmXOEYhY7A53/0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From:Subject; b=plqGOK85gxvVU3WibXDAxN1JCHUtW8XwiCcIfvkAK7oJxWv6p314ypwr4qN4is4I77AlkEx6rAnC5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iQYHHu2ACzIdt6TGKnNnOs RfZcEFWa4iLVIAe7ahx6dytbL4znjapI.gHyokQJq0vDFrNrstEsTgSgytpd0GQCL7ybhpYfr4M1 29erJnsdPE4DiSG16VOUAMbqblAdBJxN6aj0E9WWI1XEJrrA8IP6rBfya9dLZB0TfNwz7MaCecQK lKC8SdiVhkItNUV.bM4lkag5bsMwLtobUGCUMxHO_3xRWFk4WyEsuHwJ01kLAf8tXEzPUJi3oiA8 pEx8xem1hBZXFA3F4CX.vbszNdZ1NPAmSO74TNXjvYdglN2eia6Nb_z_kRaVuZT.dUIkbs0ymxEt .DwCvMEYfW.zF8Msl7ME8q_HyoO0mjtb10c5vsLagembBCl_Z.elpx43yJpbLp_HWjNRYPpLC73E ipijNpm0IxlHYtIJv61XfGyn9mZV8sWQ7ucS7vFAa_I0DtSWFythtfD4anizmitCOmwjqm5qgJ90 uHcNlVUciMjkbAYr0S1lJo0QUiAkFcIQ.F_4r39Vy1FXc535sPxyZskIpJq3KVYvsHjbz4.6pLIQ F488l_GrXgZ_frojj57fytKNYGhlFsd7hL2D7r_fbI6Wk6FuzufnLm6.0POFjYC8kjrqh5MG0SXZ K Received: from sonic.gate.mail.ne1.yahoo.com by sonic304.consmr.mail.gq1.yahoo.com with HTTP; Fri, 24 Jan 2020 06:15:39 +0000 Received: by smtp409.mail.gq1.yahoo.com (Oath Hermes SMTP Server) with ESMTPA ID 72d0469e1612faf085278699e31b4664; Fri, 24 Jan 2020 06:15:37 +0000 (UTC) Date: Fri, 24 Jan 2020 14:15:31 +0800 From: Gao Xiang To: Eric Biggers Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, Alexander Viro , Daniel Rosenberg , Gabriel Krisman Bertazi Subject: Re: [PATCH] ext4: fix race conditions in ->d_compare() and ->d_hash() Message-ID: <20200124061525.GA2407@hsiangkao-HP-ZHAN-66-Pro-G1> References: <20200124041234.159740-1-ebiggers@kernel.org> <20200124050423.GA31271@hsiangkao-HP-ZHAN-66-Pro-G1> <20200124051601.GB832@sol.localdomain> <20200124053415.GC31271@hsiangkao-HP-ZHAN-66-Pro-G1> <20200124054256.GC832@sol.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200124054256.GC832@sol.localdomain> User-Agent: Mutt/1.10.1 (2018-07-13) X-Mailer: WebService/1.1.14873 hermes Apache-HttpAsyncClient/4.1.4 (Java/1.8.0_181) Content-Length: 1754 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu, Jan 23, 2020 at 09:42:56PM -0800, Eric Biggers wrote: > On Fri, Jan 24, 2020 at 01:34:23PM +0800, Gao Xiang wrote: > > On Thu, Jan 23, 2020 at 09:16:01PM -0800, Eric Biggers wrote: > > > > [] > > > > > So we need READ_ONCE() to ensure that a consistent value is used. > > > > By the way, my understanding is all pointer could be accessed > > atomicly guaranteed by compiler. In my opinion, we generally > > use READ_ONCE() on pointers for other uses (such as, avoid > > accessing a variable twice due to compiler optimization and > > it will break some logic potentially or need some data > > dependency barrier...) > > > > Thanks, > > Gao Xiang > > But that *is* why we need READ_ONCE() here. Without it, there's no guarantee > that the compiler doesn't load the variable twice. Please read: > https://github.com/google/ktsan/wiki/READ_ONCE-and-WRITE_ONCE After scanning the patch, it seems the parent variable (dentry->d_parent) only referenced once as below: - struct inode *inode = dentry->d_parent->d_inode; + const struct dentry *parent = READ_ONCE(dentry->d_parent); + const struct inode *inode = READ_ONCE(parent->d_inode); So I think it is enough as const struct inode *inode = READ_ONCE(dentry->d_parent->d_inode); to access parent inode once to avoid parent inode being accessed for more time (and all pointers dereference should be in atomic by compilers) as one reason on if (!inode || !IS_CASEFOLDED(inode) || ... or etc. Thanks for your web reference, I will look into it. I think there is no worry about dentry->d_parent here because of this only one dereference on dentry->d_parent. You could ignore my words anyway, just my little thought though. Other part of the patch is ok. Thanks, Gao Xiang > > - Eric