Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1257745pxb; Wed, 10 Feb 2021 04:16:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzBrzkmwnuaX4dW8SIdStf+lIFiKVPAU6hgWbewQ0sYqBBXJwkXzYbhTHkrMrGpSA56kmyb X-Received: by 2002:aa7:d60f:: with SMTP id c15mr2873754edr.291.1612959386103; Wed, 10 Feb 2021 04:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612959386; cv=none; d=google.com; s=arc-20160816; b=rAu1DhpiHCiPB2ce7fmNW0Gi5aCUQxBOAk3CFcIMcFf17NHX1/aAEdhTHIxzZA5akA D/FTgOGI30C5ydaVrBlKu7BLUA2dB1xN8zV0mnfPY8pDzVd/gmWmXlwHSo0P48bx9i66 Yh6LSUWWiBFjsEX8BarXr3fSFuDuf9J4nQ6zytsiwWpdps6ftMmulYZDxU3hQ2RVg3lK ptXo0Hdjo6yBCkzZBSb5fRLcFs7D4V0MglG5Lc4yrxuuLGp7Eu30PdD/BSZdc77V2nuz 52PPTC1UdO/REIolFaXvDkfH8ag79VBlWUjrIIrAaWiNV/pzfp9i1xhNVACfQLWF/kDD qBow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=uLvd5rrui1nUVLwhWHRR2Q2Aug/VpuyG8Jcs7zI4M4k=; b=thNivMlKauoX1c0WLHRsprfzCBQyp20IlcIdVHoU+NGNypea3daqpBcjgPz6DkOZ7m 7tdCxIajsd33DJ3DnzVo0txWxtTubxp4NoGz6CnOkNunMCjjhXz6dDW76M0IrY5iyVnz 0HK/pTiNCySNv5WnBaLc8x06AZ/xkzsYyvDZ0brgIgybEQ4B60n8tGgTuMRDhQKE0T31 8z1du+v40vrIZN7wITrWHLD9zgSKzQpaMF1MjtS3qvrNxrGSgNtvAe4KEIkTEoI7uy3q BucbO493LKomdcuE1cUbo9OEMOn2yJpVwquD58aBsHfGrJ8T8HyMglNvQXNT78aQSilF +VNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=JxtImahq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bk20si1206111ejb.203.2021.02.10.04.16.01; Wed, 10 Feb 2021 04:16:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=@kernel.org header.s=k20201202 header.b=JxtImahq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbhBJMMn (ORCPT + 99 others); Wed, 10 Feb 2021 07:12:43 -0500 Received: from mail.kernel.org ([198.145.29.99]:36794 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbhBJMKG (ORCPT ); Wed, 10 Feb 2021 07:10:06 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2F2F264E31; Wed, 10 Feb 2021 12:09:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1612958966; bh=kqqb49qXsasdkSstetjMzcEMKwXctHVPfjOZKYUSEQ8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=JxtImahqfsyEYtMz027sJyToIJwi0xLfP+wZBfojfVJrVrf2FV6/SvU5fzG2RSk5Y AMCwFdgS0MQxsrM9el7SkeziYHT9YKMUCcEmsY/yI0t83orL82gMT8pitm3tj+YClM QPQh9u3xGHlM97kgEtq5WtajDfusMAjDO2/sY25UWr/pcowkSwzWYGP0azR6CWX3iX QK8f+h5vYoun5WlHcwlPbqjUM7/bKaGUaxxJVTtcPrsfGQfSeEcUpWrhi4jShu1FUo 95j4lYugp3n+fhW064Chhym7tipTMizLPqf2DVNk4o0ggBM2hx7mCY3zwv0jYkIJkS /LhAwhybrYcaw== Subject: Re: [PATCH] erofs: initialized fields can only be observed after bit is set To: Gao Xiang , linux-erofs@lists.ozlabs.org Cc: LKML , stable@vger.kernel.org References: <20210209130618.15838-1-hsiangkao.ref@aol.com> <20210209130618.15838-1-hsiangkao@aol.com> From: Chao Yu Message-ID: Date: Wed, 10 Feb 2021 20:09:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <20210209130618.15838-1-hsiangkao@aol.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Xiang, On 2021/2/9 21:06, Gao Xiang via Linux-erofs wrote: > From: Gao Xiang > > Currently, although set_bit() & test_bit() pairs are used as a fast- > path for initialized configurations. However, these atomic ops are > actually relaxed forms. Instead, load-acquire & store-release form is > needed to make sure uninitialized fields won't be observed in advance > here (yet no such corresponding bitops so use full barriers instead.) > > Fixes: 62dc45979f3f ("staging: erofs: fix race of initializing xattrs of a inode at the same time") > Fixes: 152a333a5895 ("staging: erofs: add compacted compression indexes support") > Cc: # 5.3+ > Reported-by: Huang Jianan > Signed-off-by: Gao Xiang > --- > fs/erofs/xattr.c | 10 +++++++++- > fs/erofs/zmap.c | 10 +++++++++- > 2 files changed, 18 insertions(+), 2 deletions(-) > > diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c > index 5bde77d70852..47314a26767a 100644 > --- a/fs/erofs/xattr.c > +++ b/fs/erofs/xattr.c > @@ -48,8 +48,14 @@ static int init_inode_xattrs(struct inode *inode) > int ret = 0; > > /* the most case is that xattrs of this inode are initialized. */ > - if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) > + if (test_bit(EROFS_I_EA_INITED_BIT, &vi->flags)) { > + /* > + * paired with smp_mb() at the end of the function to ensure > + * fields will only be observed after the bit is set. > + */ > + smp_mb(); I can understand below usage, since w/o smp_mb(), xattr initialization could be done after set_bit(EROFS_I_EA_INITED_BIT), then other apps could see out-of-update xattr info after that bit check. So what out-of-order execution do we need to avoid by adding above barrier? Thanks, > + /* paired with smp_mb() at the beginning of the function. */ > + smp_mb(); > set_bit(EROFS_I_EA_INITED_BIT, &vi->flags);