Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1529720rdb; Sat, 3 Feb 2024 09:57:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IEEI+SGxnf+bRhP84CT9+3nsKAsjdVVcpInz1eiOHkPtTaqdomk4FMzdk07uyuWQ4yEBn8b X-Received: by 2002:a17:906:538f:b0:a36:f974:6a25 with SMTP id g15-20020a170906538f00b00a36f9746a25mr3643183ejo.55.1706983068626; Sat, 03 Feb 2024 09:57:48 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706983068; cv=pass; d=google.com; s=arc-20160816; b=Ndd9lbdkgdPH8JIt86e7W1itekSstB/abhFTKOWagMueEHuOKlnVblnCEw2/XuhOGC MPQcggxExq22W6eF1tywbEYrecJY0JkH/uOKe2qAcpaQbtdhJnZuyUCEoYFbWNtsYBgq 82CJueLCeJvsL4nxQ/pe5ztJ3v+XVWFK9ZH4CPEULLes/8QTY6ONFZr2R6uCOha2W2ix pBouFMaRnXmfl8VRVyw/4nnF5f939fp1W6WGEGSAE0/2plT709P2Rmtj2ahdNnGekTLO E1W9qpYk3rm8V5nAqGSnyU+ddrBX5UkMcg8fHN+lSQFiFKq0xCxbhZE7XZhdaqIbHczC J6bg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=PIvmql/b6IcoymoMAhVlPKQhnLvNYMHHW5GYReOxLtU=; fh=8gLYF13/WXWUv+gT3Qvzc8+lFyCncbLuZd4Dw3DOVBk=; b=JT2xB77vyO9emJg7JHtGCOREW39nwe2N5fx6rtxQK6sa2Lru4jgVCyH1LxipMczxdf BJn9OocIw8z4I7E7YQ+Z6b/Fwkvykru3RJDSXuBUxEMUyYefM7zOxhmLVIxmqozU1nRj TJI9Nsq5CQsZ+eO52bf0LufuOk41PQpAFHzQWvEWdxaHW7gTtSha6sHghOELIBCahuoY vDPNumezIx5iGLmDxT50xdJO5HTxTq5aUJLOb313gQ6Fl6JyIdflnqXIu3efrvy6oV1T lcgVpoWl8rpZNJQsiLLRv2yf+JWqUsyZYNtN4n2TsxBLiYph+dCcGK0Pex/ZmsFnOR66 cyhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@mit.edu header.s=outgoing header.b=XUp703cP; arc=pass (i=1 spf=pass spfdomain=mit.edu dkim=pass dkdomain=mit.edu dmarc=pass fromdomain=mit.edu); spf=pass (google.com: domain of linux-ext4+bounces-1072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1072-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mit.edu X-Forwarded-Encrypted: i=1; AJvYcCXAKK4Cx/YGmM7gDcr9ZeZin/eRpy2/xLl8BZrpaSg1n7elwaPOKZKS8CZY3JCXDkVrDmX4SCIn+1byZlsIqK+ZdiqFH/iVg4x5E3DUSQ== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id cf11-20020a170906b2cb00b00a3660f5cdb1si2111527ejb.352.2024.02.03.09.57.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 03 Feb 2024 09:57:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1072-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; dkim=pass header.i=@mit.edu header.s=outgoing header.b=XUp703cP; arc=pass (i=1 spf=pass spfdomain=mit.edu dkim=pass dkdomain=mit.edu dmarc=pass fromdomain=mit.edu); spf=pass (google.com: domain of linux-ext4+bounces-1072-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1072-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=mit.edu 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 A2B7A1F24022 for ; Sat, 3 Feb 2024 17:57:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D9265FBA8; Sat, 3 Feb 2024 17:57:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=mit.edu header.i=@mit.edu header.b="XUp703cP" X-Original-To: linux-ext4@vger.kernel.org Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) (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 0FCAB5F482 for ; Sat, 3 Feb 2024 17:57:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.9.28.11 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706983046; cv=none; b=mpH79IWoNpy25DPTKvBAmLzhfUuLvqqRcgoKejvp84tFEh8UN74uB/sXA94gyJzgOiCKvxYVo/XsWowcLdABLgvj/alDB9CNl8uCcCYoQk4Jqr/kz8Hc9CckoJZFQYBF4Z35j0lxNb82v9CtPBC49nC46LKs8/jlrZA5gTsyh6w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706983046; c=relaxed/simple; bh=jxikJnui4qVASYJwKxqS8vDGGr7p1uCmUe68FiuwKdE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=nkEQOf6AGw4lRRVNWwJyp7oVsgpy7+Pg0TLTVH19swRvJ+35dq9g924gvxyqIvB+sgNyoUywtcNoKKbi9UJt/7X/LIVLjaBZN7HzfxGGAR/x0ont934ELLxG8ON7ViSvySqURgoLty+VzJB5lh0ARlQQFcWIcCqxNH3er/Dd6oE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mit.edu; spf=pass smtp.mailfrom=mit.edu; dkim=pass (2048-bit key) header.d=mit.edu header.i=@mit.edu header.b=XUp703cP; arc=none smtp.client-ip=18.9.28.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=mit.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mit.edu Received: from cwcc.thunk.org (pool-173-48-82-236.bstnma.fios.verizon.net [173.48.82.236]) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id 413HuPjn016713 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 3 Feb 2024 12:56:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mit.edu; s=outgoing; t=1706982989; bh=PIvmql/b6IcoymoMAhVlPKQhnLvNYMHHW5GYReOxLtU=; h=Date:From:Subject:Message-ID:MIME-Version:Content-Type; b=XUp703cPR/HSw0a8/8lfRjHaqFn9t0WI+Nv1Lqu4oCneg0qSBOCIaRVhWoBMvFihE hubkxs4n3OSP8nyltNh3CnWnX+6rChgqSOeRDOQL6OkR+6FFuwHaLWsjG/44cG6sm+ BVNP9XtIwPisO6tQX6KR/gO7X779mL6VQ8DS8niiCm0egq86yc/jZChwjP/+5MO3S/ /k9cpxNbznjwQJEtH/+wy0KKikGmGzDYLeYQMQNY/HKasecyoCxovE06wz2errblKo gDRBkBZlbdz3eTt8edpqxIoUUG6BiWy/pl/HalkbSdkd9nm7trgO65IOjeer9fq/IN F2mZwWFUw1OEw== Received: by cwcc.thunk.org (Postfix, from userid 15806) id E425915C02FC; Sat, 3 Feb 2024 12:56:25 -0500 (EST) Date: Sat, 3 Feb 2024 12:56:25 -0500 From: "Theodore Ts'o" To: Zhang Yi Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: Re: [PATCH v3 02/26] ext4: convert to exclusive lock while inserting delalloc extents Message-ID: <20240203175625.GE36616@mit.edu> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> <20240127015825.1608160-3-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240127015825.1608160-3-yi.zhang@huaweicloud.com> On Sat, Jan 27, 2024 at 09:58:01AM +0800, Zhang Yi wrote: > From: Zhang Yi > > ext4_da_map_blocks() only hold i_data_sem in shared mode and i_rwsem > when inserting delalloc extents, it could be raced by another querying > path of ext4_map_blocks() without i_rwsem, .e.g buffered read path. > Suppose we buffered read a file containing just a hole, and without any > cached extents tree, then it is raced by another delayed buffered write > to the same area or the near area belongs to the same hole, and the new > delalloc extent could be overwritten to a hole extent. > > pread() pwrite() > filemap_read_folio() > ext4_mpage_readpages() > ext4_map_blocks() > down_read(i_data_sem) > ext4_ext_determine_hole() > //find hole > ext4_ext_put_gap_in_cache() > ext4_es_find_extent_range() > //no delalloc extent > ext4_da_map_blocks() > down_read(i_data_sem) > ext4_insert_delayed_block() > //insert delalloc extent > ext4_es_insert_extent() > //overwrite delalloc extent to hole > > This race could lead to inconsistent delalloc extents tree and > incorrect reserved space counter. Fix this by converting to hold > i_data_sem in exclusive mode when adding a new delalloc extent in > ext4_da_map_blocks(). > > Cc: stable@vger.kernel.org > Signed-off-by: Zhang Yi > Suggested-by: Jan Kara > Reviewed-by: Jan Kara Thanks, applied. - Ted