Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp2641868pxu; Sat, 10 Oct 2020 02:31:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwnkMlEl4W55Ykcrso8T54/5pzYGf+SNlhIoS6s3+k1PrNxfTQTH61hevX5uR2yKYkrhjZP X-Received: by 2002:a50:c309:: with SMTP id a9mr3642682edb.199.1602322273641; Sat, 10 Oct 2020 02:31:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602322273; cv=none; d=google.com; s=arc-20160816; b=eIw7q5/96S5o93YYI5p6GVFInw/wFslr1xERoDyuqSmuV7wkzC0mbWkPie+U7jTwC2 gbgBscp707YXrIs+LXbYEqgRi5WN0uuKh0GuyRD3zmhgk4JttyopUrp0in1ZceFk6o9y YAIQOWsxjC52V+Oyy8VaOk8Ii0alcneoAKd4vyfqRbeg9CyqWHUsEQqxIZvRqxWYFZOb ImPTSexIYDxjNffdYAkz4L+NJ33HecFHNa7ogYA3ERl3eHUaXp6V7AQ6N++QDmaYMruD C32CW785LVnOV0KMKaeU1KxD9ERR0X6iVuGdVlvn422l5fkizEtuD1ZmbgSNy/w5u9CD Vndw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=fX/6DwXysqCrksQgFgb+4R3alOKyGkE2+FYcNluzFrM=; b=gXk6ZYUbaO8+WLK4ct520KzAkZUg6jdB4knSc+eFESA2CbvX642VCjYECM8owNLM9R mT09BbJk997nOMv8XMp8aDMS0teYve4Y93CxEUThG7H2ooDh2ZKj+xBfxU+NVAjw5lj4 OqIb95xDCUOMkUnvv4cXejGa9CKCMq36hfHCGRmaA2EYCOmwCnxmVZCALmSCkhei9Dw6 KB36anq8jvJ3BuaL0EK1Cz5vTCEu9TsCfVRHuGVDP7Ldr7lFf++hiXcsrOTllZ9ier8i dtzfRxdrvHiGi8jbtxBKFYj2mwloIXcpv5Cor8ACEs2eYfl1ibzIGLnmPImFPenlyWNI /D4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MwnZBF1i; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id oc24si8342294ejb.530.2020.10.10.02.30.47; Sat, 10 Oct 2020 02:31:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MwnZBF1i; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729688AbgJJIOZ (ORCPT + 99 others); Sat, 10 Oct 2020 04:14:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47330 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729876AbgJJIKW (ORCPT ); Sat, 10 Oct 2020 04:10:22 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65236C0613CF for ; Sat, 10 Oct 2020 01:10:22 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id 132so2306264pfz.5 for ; Sat, 10 Oct 2020 01:10:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=fX/6DwXysqCrksQgFgb+4R3alOKyGkE2+FYcNluzFrM=; b=MwnZBF1iUQGVFsYqwGLc+Apo7Bn30BI7DZNmscghAiu7p0fRnpIKAY/YnLwOKzU3hR 0U16qrfiUFXwDF7rPoM54LGUKPBTdXR7lyhZ0dkbSge66SY0cUR3Pvk5DdrHccuWjePn 6PntI9+5jEGHp7QL3Yp3w5KP8g/MKJ36ZpZs+BgkpKrOdk9xlrmJDaMx/g3It/d1XLi7 BXPoUHKkDlnMPq9UEISUYVKJd/EKIC6v1/2tmijjIjfQNUXFQaVO7u1Sor4p/ldUhAtb VdOlAqJzcUthROXIDMecrsY+eTD+HQAAPPDokKITHB2gpm7L0o22KSzArjjrNe7/D5ke buew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=fX/6DwXysqCrksQgFgb+4R3alOKyGkE2+FYcNluzFrM=; b=Lsg3fPhw5ojPcvOtYjRpR/K+TEwFZRHqeM5bqd70TKXPyZ312gjn3wUNktg2i8TLzX tDePVAVit1joaou60mp3fiQ2Qk71lCrbMIl61ZTsUbnBcHLr30RXbTt+0TjYHTnSPfCj oCuES4zidq9BQ1v2sOzNjyz16+ukgKIlaQt42Ub+kHL+5XIcCFdwmwnO+E/Q6TTQekQA IEgCLqJrCPbqoWt4DHru+3I2aKfkzfZMt2frZGKyJU2AuaO+bSq81uAklVfhxBPqHAEA kPlpDIspLMwjgPs+Z55flbDbvaX5y/wLakzw2hPpmt360h3IsffM02AJemoiCA3OM4+i vEtQ== X-Gm-Message-State: AOAM5338srs1XPl9pp4hDo2T7HvQP8w0/JQl20wbahPt+of+QTy/VkkD qxkcbab7F3Xw+wD8+771kfl7e8rdwG69 X-Received: by 2002:a63:5404:: with SMTP id i4mr6511763pgb.334.1602317421493; Sat, 10 Oct 2020 01:10:21 -0700 (PDT) Received: from he-cluster.localdomain (67.216.221.250.16clouds.com. [67.216.221.250]) by smtp.gmail.com with ESMTPSA id q65sm12588063pga.88.2020.10.10.01.10.20 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Oct 2020 01:10:20 -0700 (PDT) From: xiakaixu1987@gmail.com X-Google-Original-From: kaixuxia@tencent.com To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, Kaixu Xia Subject: [RFC PATCH] ext4: use the normal helper to get the actual inode Date: Sat, 10 Oct 2020 16:10:16 +0800 Message-Id: <1602317416-1260-1-git-send-email-kaixuxia@tencent.com> X-Mailer: git-send-email 1.8.3.1 Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Kaixu Xia Here we use the READ_ONCE to fix race conditions in ->d_compare() and ->d_hash() when they are called in RCU-walk mode, seems we can use the normal helper d_inode_rcu() to get the actual inode. Signed-off-by: Kaixu Xia --- fs/ext4/dir.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index 1d82336b1cd4..3bf6cb8e55f6 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -674,7 +674,7 @@ static int ext4_d_compare(const struct dentry *dentry, unsigned int len, { struct qstr qstr = {.name = str, .len = len }; const struct dentry *parent = READ_ONCE(dentry->d_parent); - const struct inode *inode = READ_ONCE(parent->d_inode); + const struct inode *inode = d_inode_rcu(parent); char strbuf[DNAME_INLINE_LEN]; if (!inode || !IS_CASEFOLDED(inode) || @@ -706,7 +706,7 @@ static int ext4_d_hash(const struct dentry *dentry, struct qstr *str) { const struct ext4_sb_info *sbi = EXT4_SB(dentry->d_sb); const struct unicode_map *um = sbi->s_encoding; - const struct inode *inode = READ_ONCE(dentry->d_inode); + const struct inode *inode = d_inode_rcu(dentry); unsigned char *norm; int len, ret = 0; -- 2.20.0