From mboxrd@z Thu Jan 1 00:00:00 1970 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=unavailable 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 8DAF7C433E0 for ; Wed, 10 Feb 2021 12:12:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5C03A64E2A for ; Wed, 10 Feb 2021 12:12:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbhBJMMM (ORCPT ); Wed, 10 Feb 2021 07:12:12 -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: stable@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);