Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB3A0C433DB for ; Wed, 10 Feb 2021 12:10:00 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DA8E64E3B for ; Wed, 10 Feb 2021 12:10:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DA8E64E3B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DbJVF6zgkzDvXZ for ; Wed, 10 Feb 2021 23:09:57 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=198.145.29.99; helo=mail.kernel.org; envelope-from=chao@kernel.org; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=JxtImahq; dkim-atps=neutral Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4DbJTj0VqZzDsk5 for ; Wed, 10 Feb 2021 23:09:28 +1100 (AEDT) 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 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 X-BeenThere: linux-erofs@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development of Linux EROFS file system List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: LKML , stable@vger.kernel.org Errors-To: linux-erofs-bounces+linux-erofs=archiver.kernel.org@lists.ozlabs.org Sender: "Linux-erofs" 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);