Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2421745lqo; Mon, 20 May 2024 05:40:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWoOoBA5yfsg0Uu6aSSSdj8uXTNrRNEKsyYm8iV2WHw0wKKj01wCXqmTUCBoJCaQfp3FEHazgUjavbjVi9ie8HLEMYACpSke6PaV4NXQ== X-Google-Smtp-Source: AGHT+IEbfiKpUIs8dGzItBtZdNEb4gE2VvJC0dlbR3aT31Wbyu7mOAjRZVTjc6hzBf0Yo2bWY9s2 X-Received: by 2002:a50:d61c:0:b0:573:1e9e:2d71 with SMTP id 4fb4d7f45d1cf-5752b4bb11dmr6492627a12.19.1716208810761; Mon, 20 May 2024 05:40:10 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716208810; cv=pass; d=google.com; s=arc-20160816; b=ni9597JKKg06Zp1+Dlbdz6CgMTU0aWnT6ntLtCJHRKez1gZiKtr0mgfDqqN1+dZitA asYu2nhWLGilxb8gO2LCHZ7EYKk/IYxaxUCXJorSNUeYzrXPewogaxomkg2nOGKm0TYE MAdDcgdRuN/0i9D1FpyDXGOyiQzkIoFc3WAcHTwz9MFQ/nwDqssfIOk/POPEuRjKIX5y cNc3Y9vkJnCl1TCIx+1TCCFuapPbXvHbZeSy/hKUFNGNbqXWAuVNKMrJYoR04wfN6wr/ DMDCKaxbp19KubkMIMMyCNeKE5QvafN7Rak1N3Q/te71JBFbETXqWSGG90auhMKz8jlb iEjQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:content-language:in-reply-to:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent:date :message-id:from:references:cc:to:subject; bh=Ci6rFPJdHY8XB6Ardd+ehRHRab5MNmNyMy17W8nLC0U=; fh=7LlI9mtb9YeS+qLGMphBztFCkF9I/Pm8wesASBK5EsA=; b=wSx1MtwrrLcLdSCOmxSJg9Milcen5PryJSre6bflkxX++op4oxRjwAuTi/azd9qZsT eht4oGIuqj+C0ru+VK+HAiO8bX/OawULXae/JQ/BPgy5DWLAhbf+5lmp0t2P6R3Kcs4V MRFT0lDUBSWJh7Q5lkkNWgkjw5WvrGyjK7DGAei/zXZ/3zRLoLdctQe8HffGUCnQlxFf t055AE6Xcp/gqwK3CKYcp4QpBocdipk5PkBEMCSd2owOZuXxhTfyG1HCDs1V+zmw9I2E yPpN8MkoE3uiWl7P3CR/O+5v6SwDFj+inGmPhTgfGX8vEnkOwXr52jWv2CLR2TbAL3s3 WnJg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-183753-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183753-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beacd08si13082056a12.87.2024.05.20.05.40.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 05:40:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183753-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-183753-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183753-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 523911F218F7 for ; Mon, 20 May 2024 12:40:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A98A35645B; Mon, 20 May 2024 12:39:59 +0000 (UTC) Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 830A050275; Mon, 20 May 2024 12:39:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208799; cv=none; b=CKKqOkurqC/mHOsbxgzY7QOZJ9WOR0fy98b+dmOCESxQJ+rP1IIdurw/7VfUCbv/SG/87qyvsTVn06HR72mbK2CeaRJCS/4ouoYlBZsY+WVVM0+J3vZ5tSfTOg3DsP1/4hM34eJkJm0K+2HKLfpRvFWxzL8uf2KY5qK/IBq9Bow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716208799; c=relaxed/simple; bh=RMALe9odXTlOhasHrwx7JoyA/Hw3+Z+zypbJzTqfiiM=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=P30tjZUr8uqFNitAxl3na9B2J2VaKWCLEiGzbQ+GgiocHCoC36mi/2oEKm1C0RGEUjMwO5h0hO+Cc9lQYv1lTtYS/Tgnq7tryInRdp9nxTyAX6Axu99PYC5VoaVEJKwQt+N/zpSxy7FQgWdDJsrE5g7vuOk44iRXf0VhYWNkqXM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vjcb24YNPz4f3l1K; Mon, 20 May 2024 20:39:42 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.75]) by mail.maildlp.com (Postfix) with ESMTP id 0A02B1A016E; Mon, 20 May 2024 20:39:53 +0800 (CST) Received: from [10.174.179.80] (unknown [10.174.179.80]) by APP2 (Coremail) with SMTP id Syh0CgDnCw+XREtma4YLNg--.33126S3; Mon, 20 May 2024 20:39:52 +0800 (CST) Subject: Re: [PATCH] ext4/jbd2: drop jbd2_transaction_committed() To: Jan Kara Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, ritesh.list@gmail.com, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com References: <20240513072119.2335346-1-yi.zhang@huaweicloud.com> <20240515002513.yaglghza4i4ldmr5@quack3> <20240520084906.ejykv3xwn7l36jbg@quack3> From: Zhang Yi Message-ID: <8d85f75e-cf9e-b3da-766f-59d80d608203@huaweicloud.com> Date: Mon, 20 May 2024 20:39:51 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.12.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <20240520084906.ejykv3xwn7l36jbg@quack3> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CM-TRANSID:Syh0CgDnCw+XREtma4YLNg--.33126S3 X-Coremail-Antispam: 1UD129KBjvJXoW7WF43Kr43Ar1UGr4rKw17Jrb_yoW8Wry5pF W8Ka47Ka17tr1Svrn7trnrZFy2yw1Ikry8Gr9F9ryqk3yUG3sagrWftryak34Du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mon 13-05-24 15:21:19, Zhang Yi wrote: >>> Also accessing j_commit_sequence without any >>> lock is theoretically problematic wrt compiler optimization. You should have >>> READ_ONCE() there and the places modifying j_commit_sequence need to use >>> WRITE_ONCE(). >>> >> >> Thanks for pointing this out, but I'm not sure if we have to need READ_ONCE() >> here. IIUC, if we add READ_ONCE(), we could make sure to get the latest >> j_commit_sequence, if not, there is a window (it might becomes larger) that >> we could get the old value and jbd2_transaction_committed() could return false >> even if the given transaction was just committed, but I think the window is >> always there, so it looks like it is not a big problem, is that right? > > Well, all accesses to any memory should use READ_ONCE(), be protected by a > lock, or use types that handle atomicity on assembly level (like atomic_t, > or atomic bit operations and similar). Otherwise the compiler is free to > assume the underlying memory cannot change and generate potentionally > invalid code. In this case, I don't think realistically any compiler will > do it but still it is a good practice and also it saves us from KCSAN > warnings. If you want to know more details about possible problems, see > > tools/memory-model/Documentation/explanation.txt > > chapter "PLAIN ACCESSES AND DATA RACES". > Sure, this document is really helpful, I'll add READ_ONCE() and WRITE_ONCE() here, thanks a lot. Yi.