From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.98 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796040012; b=bjwMJk1gRk02PHQ5saFUkn+IDAT74e6z29+SchTMaVWlhc8vlgn7u+1RjhcqLabqcFR5 O3SlbmZ0WzK89K6aj03sx117gnfSKsgoWno7ZXu65hGSz921p4/SVh6gXfCxVOBheFvEn b8+iQd4R3UfQUqVx8QDhnOIGof7pwncenrfa1z4F1XywxNLYmwXhhB3j3P9U16VUbQPRO mlxkG9gRR1Ta2VRFsLgu1D/A5NDcukMhucgk8OZYSIUdRYDocLyCTF+7myqrmCCUdf4bx o5GxqUYy6Clfn9yJzLcIV70O9XkIUwTwxQn27mjmu52WDbzAM4STTu0IPqD7Q8wZTGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796040012; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=6snv9V/YlAwpwE12/M4Lqx5KazkUg5csblHroHkt3jw=; b=O2x7qFyViGDxW/NfSm8EykHOPZQrIpCfztlGefFnFEYqdL3I9f5wuK9I/dECr+iXVIlF 4X1jTnlSzyNfw61mfV2G9L/8jZIPk+XYEtUba+hzIHDhLulH/2X8Br3PyoLUbbkUOxQIY BJHOJFUyxCp9LI6HXGYw/DM1PZJXzduXoUx2J6dawB1qS74WL18B8SigX7K9345Ro4Mg2 j78MNsWbgcSNADIXnT8t/ZJW4SHRtOHyRcDyGG4qu790BFIBYSyVrGsTrnG3pJ2vR+2Um xdBxjnad4p0gZOnWCwv6CM7UXphx6bWi6tYrGFEgs1b8SMrquGNJhtAa8jevDuneOWA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=xdompmie; arc=none smtp.remote-ip=115.124.30.98 Received: from out30-98.freemail.mail.aliyun.com (out30-98.freemail.mail.aliyun.com [115.124.30.98]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB06D606A31C for ; Mon, 30 Nov 2026 12:00:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EB06D606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=xdompmie DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796040005; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=6snv9V/YlAwpwE12/M4Lqx5KazkUg5csblHroHkt3jw=; b=xdompmien/M+4nGcz/GtPeg79HmgRra21y7ZN5czflydcYJLXWuOAha8AiSsIC+1P8FeRxVqcR9wEr+X4BQNZ4idDbMX7PNpjMEW3meng87OsxB9b7bSp/UqjT5JVqWgQSPp26OZjZNU9QlEQuTb6+e3UZBbYbCfHvN2ex08GMs= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R641e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033032089153;MF=joseph.qi@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0XFlQIyD_1796040004; Received: from 30.221.130.26(mailfrom:joseph.qi@linux.alibaba.com fp:SMTPD_---0XFlQIyD_1796040004 cluster:ay36) by smtp.aliyun-inc.com; Mon, 30 Nov 2026 20:00:04 +0800 Message-ID: <15805f4a-7a23-4538-a7af-4e2c1111afe3@linux.alibaba.com> Date: Mon, 30 Nov 2026 20:00:03 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v13 06/10] ocfs2: rework the direct write context for multi-cluster mappings To: sashiko-reviews@lists.linux.dev, Heming Zhao , Christoph Hellwig Cc: Mark Fasheh , Joel Becker , Andrew Morton , "ocfs2-devel@lists.linux.dev" , "linux-kernel@vger.kernel.org" References: <20261130100203.383093-1-joseph.qi@linux.alibaba.com> <20261130100203.383093-7-joseph.qi@linux.alibaba.com> From: Joseph Qi In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/30/26 6:28 PM, sashiko-bot@kernel.org wrote: > Thank you for your contribution! Sashiko AI review found 1 potential > issue to consider: > - [High] ocfs2: short direct write marks unzeroed partial cluster > written in ocfs2_dio_end_io_write() > -- > > commit 25ecce6352ba3b041ae3cd99d8a7842789bba66e > Author: Heming Zhao > > ocfs2: rework the direct write context for multi-cluster mappings > > This commit reworks ocfs2_write_ctxt and unwritten extent tracking to > handle multi-cluster ranges for direct writes instead of mapping one > cluster at a time. > >> diff --git a/fs/ocfs2/aops.c b/fs/ocfs2/aops.c >> index 21cdc5c29331d..e3e28584e7410 100644 >> --- a/fs/ocfs2/aops.c >> +++ b/fs/ocfs2/aops.c > [ ... ] >> @@ -1084,7 +1182,85 @@ static int ocfs2_prepare_folio_for_write(struct inode *inode, u64 *p_blkno, > [ ... ] >> +static int ocfs2_grab_folios_direct(struct address_space *mapping, >> + struct ocfs2_write_ctxt *wc, loff_t user_pos, unsigned user_len) >> +{ > [ ... ] >> + for (i = 0; i < ppc; i++) { >> + unsigned long index = start + i; >> + struct folio *folio; >> + >> + if (index >= last_index) >> + break; >> + >> + /* Track the slots in use, for the unlock/commit loops. */ >> + wc->w_num_folios = max_t(unsigned int, wc->w_num_folios, >> + win * ppc + i + 1); >> + >> + /* The direct io target has no page cache page here. */ >> + if (index >= target_index && index <= end_index) >> + continue; > [ ... ] >> @@ -2151,9 +2747,222 @@ static int ocfs2_write_end(const struct kiocb *iocb, >> return ret; >> } >> >> +/* >> + * Convert the unwritten extents of a direct write, which is finished, >> + * and change the file size if it has been extended. >> + * >> + * @head are the clusters the write has zeroed or allocated, recorded by >> + * ocfs2_dio_wr_map_blocks(). Those which are not covered by the data >> + * written, [offset, offset + bytes), are left unwritten. >> + */ >> +static int ocfs2_dio_end_io_write(struct inode *inode, >> + loff_t offset, >> + ssize_t bytes, >> + struct list_head *head) >> +{ >> + struct ocfs2_cached_dealloc_ctxt dealloc; >> + struct ocfs2_extent_tree et; >> + struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); >> + struct ocfs2_inode_info *oi = OCFS2_I(inode); >> + struct ocfs2_unwritten_extent *ue; >> + struct buffer_head *di_bh = NULL; >> + struct ocfs2_dinode *di; >> + struct ocfs2_alloc_context *data_ac = NULL; >> + struct ocfs2_alloc_context *meta_ac = NULL; >> + handle_t *handle = NULL; >> + loff_t end = offset + bytes; >> + int ret = 0, credits = 0, batch = 0, pass; >> + u32 first_cpos, last_cpos; >> + u32 extents_to_split = 0; >> + >> + first_cpos = offset >> osb->s_clustersize_bits; >> + last_cpos = ocfs2_clusters_for_bytes(inode->i_sb, end); > > [Severity: High] > Can a short direct write to a hole or unwritten extent within i_size cause > ocfs2_dio_end_io_write() to mark an unzeroed partial cluster as written, > exposing stale disk blocks? > > When s_clustersize > PAGE_SIZE, ocfs2_grab_folios_direct() skips zeroing > all pages in [target_index, end_index] and all middle clusters, assuming > direct I/O will overwrite the entire mapped range [user_pos, user_pos + > user_len). If the write stops short (for example, pwritev() faults on a > later iovec after submitting the first page of a cluster), the remaining > blocks of that cluster in [end, user_pos + user_len) are neither written > by direct I/O nor zeroed through the page cache. Rounding end up with > ocfs2_clusters_for_bytes() into last_cpos then converts the entire cluster > containing end - 1 from OCFS2_EXT_UNWRITTEN to written. > This seems a false postive finding. In this patch the direct write path is still the buffer_head one: ocfs2_direct_IO() calls __blockdev_direct_IO(), and that core already zeroes the outstanding mapped blocks when a write faults partway through a mapping. Thanks, Joseph