From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-003.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-003.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.72.182.33]) (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 EFB0C1369B4; Tue, 21 Oct 2025 07:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.72.182.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030587; cv=none; b=sO8qeh8TJAjiA7FIpCkWRmBQAbW84gdlNJgITDz6qv958q63RyFjSyVIXzuM6rEZ40kY7RpZyAKuwPUTFxp9c1y+AtEm31Y/pnXe084X6nRzJJzzpVkv6Ez5VCXPU5bgdHcov87YJxnJ3RnPkdeqPfk9TWOqoYo88hBXddaypFo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030587; c=relaxed/simple; bh=xUSk8LiAjBR7wIY9a1W1AM/GYvH5kT/DZkSS34KxDMM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mhirVlnNAIHubuc6Z9t9XT2nVshAIbtP4uCycTZTRl6g9rF5Xg30yU9SjB0YpqWEpZBMflCxZguV23WSkdVBJj8z4nhdE7weZonLaEAwplNYMWBpASKxjhqk0yqE/iIDC3Z8HVOYUOSvqaqB9B6tifXHQAcHcXBh940W7feC4D0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=EossVXMv; arc=none smtp.client-ip=3.72.182.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="EossVXMv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030583; x=1792566583; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IRrO90fketCOWk9bfh6aaz0EBHE6DKiahtipOxhwoDQ=; b=EossVXMvvN620OzMFydwN38Q+dSohdkJ0u2MAistdkiXFELcteFT5149 R3LhEbwrHJTEeW6ubz16FW5/KEPOxIJhebz9L/N6jC3Qv9GPaYvosWPIA IPsAjhI+wO3+bUC49sMv18tOuhxEIP/rgWOXwO7H4PhyG3aq93gPxmmP3 7CjZEcrrYYM1CnPaOhvXy2AnjbkSE56rKHSQZH08wg1Gjau12NcpNjGqr T7FK7MQIa3qQB+rnwuky09rNfbP0sxk2yEZl2XsY+FffDGDX0E/ZE0j8w lh2HTU7E4ftTATorEg4AHg9EzzNU6+wVrFs+K7sTTzG+xkGRDGY0CjkHH g==; X-CSE-ConnectionGUID: TslvYmjVRZ67KeFhlmCKUA== X-CSE-MsgGUID: BZ4tqt3BSO+r/jg1BcNIPQ== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3938994" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-003.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:09:31 +0000 Received: from EX19MTAEUB001.ant.amazon.com [54.240.197.226:2712] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.15.203:2525] with esmtp (Farcaster) id 3b019c0e-37f5-4041-9549-5b8fdb60007b; Tue, 21 Oct 2025 07:09:31 +0000 (UTC) X-Farcaster-Flow-ID: 3b019c0e-37f5-4041-9549-5b8fdb60007b Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:09:28 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:09:18 +0000 From: Mahmoud Adam To: CC: , , Christoph Hellwig , Damien Le Moal , Hannes Reinecke , "Darrick J. Wong" , Al Viro , Andreas Gruenbacher , "Anna Schumaker" , Chao Yu , Christian Brauner , Ilya Dryomov , Jaegeuk Kim , Jens Axboe , Johannes Thumshirn , Matthew Wilcox , "Miklos Szeredi" , Miklos Szeredi , "Theodore Ts'o" , Trond Myklebust , Xiubo Li , Andrew Morton , "Jeff Layton" , Andreas Dilger , Christoph Hellwig , Ryusuke Konishi , Luis Chamberlain , , , , , , , , , , Subject: [PATCH 6.1 1/8] filemap: add a kiocb_invalidate_pages helper Date: Tue, 21 Oct 2025 09:03:36 +0200 Message-ID: <20251021070353.96705-3-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D045UWA003.ant.amazon.com (10.13.139.46) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christoph Hellwig commit e003f74afbd2feadbb9ffbf9135e2d2fb5d320a5 upstream. Factor out a helper that calls filemap_write_and_wait_range and invalidate_inode_pages2_range for the range covered by a write kiocb or returns -EAGAIN if the kiocb is marked as nowait and there would be pages to write or invalidate. Link: https://lkml.kernel.org/r/20230601145904.1385409-6-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong Cc: Al Viro Cc: Andreas Gruenbacher Cc: Anna Schumaker Cc: Chao Yu Cc: Christian Brauner Cc: Ilya Dryomov Cc: Jaegeuk Kim Cc: Jens Axboe Cc: Johannes Thumshirn Cc: Matthew Wilcox Cc: Miklos Szeredi Cc: Miklos Szeredi Cc: Theodore Ts'o Cc: Trond Myklebust Cc: Xiubo Li Signed-off-by: Andrew Morton Signed-off-by: Mahmoud Adam --- include/linux/pagemap.h | 1 + mm/filemap.c | 48 ++++++++++++++++++++++++----------------- 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 1be5a1fa6a3a84..bb462e5a91e28d 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -30,6 +30,7 @@ static inline void invalidate_remote_inode(struct inode *= inode) int invalidate_inode_pages2(struct address_space *mapping); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); int filemap_flush(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index 2ae6c6146d848a..0923b8df285886 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2839,6 +2839,33 @@ ssize_t filemap_read(struct kiocb *iocb, struct iov_= iter *iter, } EXPORT_SYMBOL_GPL(filemap_read); =20 +int kiocb_invalidate_pages(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping =3D iocb->ki_filp->f_mapping; + loff_t pos =3D iocb->ki_pos; + loff_t end =3D pos + count - 1; + int ret; + + if (iocb->ki_flags & IOCB_NOWAIT) { + /* we could block if there are any pages in the range */ + if (filemap_range_has_page(mapping, pos, end)) + return -EAGAIN; + } else { + ret =3D filemap_write_and_wait_range(mapping, pos, end); + if (ret) + return ret; + } + + /* + * After a write we want buffered reads to be sure to go to disk to get + * the new data. We invalidate clean cached page from the region we're + * about to write. We do this *before* the write so that we can return + * without clobbering -EIOCBQUEUED from ->direct_IO(). + */ + return invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, + end >> PAGE_SHIFT); +} + /** * generic_file_read_iter - generic filesystem read routine * @iocb: kernel I/O control block @@ -3737,30 +3764,11 @@ generic_file_direct_write(struct kiocb *iocb, struc= t iov_iter *from) write_len =3D iov_iter_count(from); end =3D (pos + write_len - 1) >> PAGE_SHIFT; =20 - if (iocb->ki_flags & IOCB_NOWAIT) { - /* If there are pages to writeback, return */ - if (filemap_range_has_page(file->f_mapping, pos, - pos + write_len - 1)) - return -EAGAIN; - } else { - written =3D filemap_write_and_wait_range(mapping, pos, - pos + write_len - 1); - if (written) - goto out; - } - - /* - * After a write we want buffered reads to be sure to go to disk to get - * the new data. We invalidate clean cached page from the region we're - * about to write. We do this *before* the write so that we can return - * without clobbering -EIOCBQUEUED from ->direct_IO(). - */ - written =3D invalidate_inode_pages2_range(mapping, - pos >> PAGE_SHIFT, end); /* * If a page can not be invalidated, return 0 to fall back * to buffered write. */ + written =3D kiocb_invalidate_pages(iocb, write_len); if (written) { if (written =3D=3D -EBUSY) return 0; --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-003.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-003.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.72.182.33]) (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 37FA92737F6; Tue, 21 Oct 2025 07:10:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.72.182.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030604; cv=none; b=S1JSKZMG+ECW9vUeKKnQ/+Lo9z7LTJP86DpUHABu+z0VJexDSzpraD2csOJaUVmSK5CEg0Igt9YSsfZ91DvICepCT1KXoUM8wVSacn4QCIsUp8R2jarrusRBIeqFtif3afDCeH8LWQZ6zLKXYkYnfbQ7uHD1dyi+gr4/8pGBlWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030604; c=relaxed/simple; bh=lVvsV5rW7CuZZaMc1NIWyfTh/22AIUZxBL01RldT99o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F/1m813p0spCEDKs5+e/OotFde0kyi8KlwwJpiRReY9TxJHnTBdza7sa8+QZ2CyapRJMEcUH3ypaZ89z85E2iIpf9S0ub/wuWBbDFWNsYky5R2J2EGG2FVGqd7thNPvfx3aMpSTKJJgPdWbTAcc1OSfnaBP+GmWqZLMJch28mgY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=dik6jM5D; arc=none smtp.client-ip=3.72.182.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="dik6jM5D" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030602; x=1792566602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c9ehURESYE/FlGbnKhMBWJDg3bnRGJGCmyBZSmWKczc=; b=dik6jM5DfDfKT0dR6kaTBo5FoaizFbTJxqftkYYfUeJRXIyFmmBH96CG 00El+WbsZekOsqcltqMCjVLBjbBZBTHxsCO1aZd15WKKZ00eaqK5SRHh5 oChnHqZZiUR8qM6crskA9PmOHaw3paiHcRLs+m+k8AZVQSqPQaFfckvp1 xg6lGzEhhppzWNUFuJ6THOgLcDhbJ6zwMW7i0ezqwz/XMgH+ASRJaPLda u0bf3Y0aJ3ukGvjXtEFMnRsIdMWi8s7iJH1hi34yuqAKOtUGqKj1eWNx1 w3xvblNYCqSYoY6TLiWYU81VntuVfEKKPQMnSpN/2MZ7+AK1rMJfS1NvU g==; X-CSE-ConnectionGUID: bVruJ4WDRMK5ZgB6aLYZ9g== X-CSE-MsgGUID: ey+Ss73iRgm2E0Ht00LPgQ== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3939069" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-003.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:09:59 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:28056] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.11.58:2525] with esmtp (Farcaster) id 533d5b60-49a1-492a-8ab5-004364c4dd08; Tue, 21 Oct 2025 07:09:59 +0000 (UTC) X-Farcaster-Flow-ID: 533d5b60-49a1-492a-8ab5-004364c4dd08 Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:09:59 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:09:48 +0000 From: Mahmoud Adam To: CC: , , Christoph Hellwig , Damien Le Moal , Hannes Reinecke , "Darrick J. Wong" , Al Viro , Andreas Gruenbacher , "Anna Schumaker" , Chao Yu , Christian Brauner , Ilya Dryomov , Jaegeuk Kim , Jens Axboe , Johannes Thumshirn , Matthew Wilcox , "Miklos Szeredi" , Miklos Szeredi , "Theodore Ts'o" , Trond Myklebust , Xiubo Li , Andrew Morton , "Jeff Layton" , Andreas Dilger , Christoph Hellwig , Ryusuke Konishi , Luis Chamberlain , , , , , , , , , , Subject: [PATCH 6.1 2/8] filemap: add a kiocb_invalidate_post_direct_write helper Date: Tue, 21 Oct 2025 09:03:37 +0200 Message-ID: <20251021070353.96705-4-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D033UWA002.ant.amazon.com (10.13.139.10) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christoph Hellwig commit c402a9a9430b670926decbb284b756ee6f47c1ec upstream. Add a helper to invalidate page cache after a dio write. Link: https://lkml.kernel.org/r/20230601145904.1385409-7-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Acked-by: Darrick J. Wong Cc: Al Viro Cc: Andreas Gruenbacher Cc: Anna Schumaker Cc: Chao Yu Cc: Christian Brauner Cc: Ilya Dryomov Cc: Jaegeuk Kim Cc: Jens Axboe Cc: Johannes Thumshirn Cc: Matthew Wilcox Cc: Miklos Szeredi Cc: Miklos Szeredi Cc: Theodore Ts'o Cc: Trond Myklebust Cc: Xiubo Li Signed-off-by: Andrew Morton Signed-off-by: Mahmoud Adam --- fs/direct-io.c | 10 ++-------- fs/iomap/direct-io.c | 12 ++---------- include/linux/fs.h | 5 ----- include/linux/pagemap.h | 1 + mm/filemap.c | 37 ++++++++++++++++++++----------------- 5 files changed, 25 insertions(+), 40 deletions(-) diff --git a/fs/direct-io.c b/fs/direct-io.c index 03d381377ae10a..514042f12aea76 100644 --- a/fs/direct-io.c +++ b/fs/direct-io.c @@ -286,14 +286,8 @@ static ssize_t dio_complete(struct dio *dio, ssize_t r= et, unsigned int flags) * zeros from unwritten extents. */ if (flags & DIO_COMPLETE_INVALIDATE && - ret > 0 && dio_op =3D=3D REQ_OP_WRITE && - dio->inode->i_mapping->nrpages) { - err =3D invalidate_inode_pages2_range(dio->inode->i_mapping, - offset >> PAGE_SHIFT, - (offset + ret - 1) >> PAGE_SHIFT); - if (err) - dio_warn_stale_pagecache(dio->iocb->ki_filp); - } + ret > 0 && dio_op =3D=3D REQ_OP_WRITE) + kiocb_invalidate_post_direct_write(dio->iocb, ret); =20 inode_dio_end(dio->inode); =20 diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index 105c4a1d20a20b..9acfc9e847cdcb 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -81,7 +81,6 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) { const struct iomap_dio_ops *dops =3D dio->dops; struct kiocb *iocb =3D dio->iocb; - struct inode *inode =3D file_inode(iocb->ki_filp); loff_t offset =3D iocb->ki_pos; ssize_t ret =3D dio->error; =20 @@ -108,15 +107,8 @@ ssize_t iomap_dio_complete(struct iomap_dio *dio) * ->end_io() when necessary, otherwise a racing buffer read would cache * zeros from unwritten extents. */ - if (!dio->error && dio->size && - (dio->flags & IOMAP_DIO_WRITE) && inode->i_mapping->nrpages) { - int err; - err =3D invalidate_inode_pages2_range(inode->i_mapping, - offset >> PAGE_SHIFT, - (offset + dio->size - 1) >> PAGE_SHIFT); - if (err) - dio_warn_stale_pagecache(iocb->ki_filp); - } + if (!dio->error && dio->size && (dio->flags & IOMAP_DIO_WRITE)) + kiocb_invalidate_post_direct_write(iocb, dio->size); =20 inode_dio_end(file_inode(iocb->ki_filp)); if (ret > 0) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 48758ab2910087..4e8a3e4f894c0f 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3371,11 +3371,6 @@ static inline void inode_dio_end(struct inode *inode) wake_up_bit(&inode->i_state, __I_DIO_WAKEUP); } =20 -/* - * Warn about a page cache invalidation failure diring a direct I/O write. - */ -void dio_warn_stale_pagecache(struct file *filp); - extern void inode_set_flags(struct inode *inode, unsigned int flags, unsigned int mask); =20 diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index bb462e5a91e28d..dfaa0990186716 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -31,6 +31,7 @@ int invalidate_inode_pages2(struct address_space *mapping= ); int invalidate_inode_pages2_range(struct address_space *mapping, pgoff_t start, pgoff_t end); int kiocb_invalidate_pages(struct kiocb *iocb, size_t count); +void kiocb_invalidate_post_direct_write(struct kiocb *iocb, size_t count); int write_inode_now(struct inode *, int sync); int filemap_fdatawrite(struct address_space *); int filemap_flush(struct address_space *); diff --git a/mm/filemap.c b/mm/filemap.c index 0923b8df285886..39484af4300e3c 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3733,7 +3733,7 @@ EXPORT_SYMBOL(read_cache_page_gfp); /* * Warn about a page cache invalidation failure during a direct I/O write. */ -void dio_warn_stale_pagecache(struct file *filp) +static void dio_warn_stale_pagecache(struct file *filp) { static DEFINE_RATELIMIT_STATE(_rs, 86400 * HZ, DEFAULT_RATELIMIT_BURST); char pathname[128]; @@ -3750,19 +3750,23 @@ void dio_warn_stale_pagecache(struct file *filp) } } =20 +void kiocb_invalidate_post_direct_write(struct kiocb *iocb, size_t count) +{ + struct address_space *mapping =3D iocb->ki_filp->f_mapping; + + if (mapping->nrpages && + invalidate_inode_pages2_range(mapping, + iocb->ki_pos >> PAGE_SHIFT, + (iocb->ki_pos + count - 1) >> PAGE_SHIFT)) + dio_warn_stale_pagecache(iocb->ki_filp); +} + ssize_t generic_file_direct_write(struct kiocb *iocb, struct iov_iter *from) { - struct file *file =3D iocb->ki_filp; - struct address_space *mapping =3D file->f_mapping; - struct inode *inode =3D mapping->host; - loff_t pos =3D iocb->ki_pos; - ssize_t written; - size_t write_len; - pgoff_t end; - - write_len =3D iov_iter_count(from); - end =3D (pos + write_len - 1) >> PAGE_SHIFT; + struct address_space *mapping =3D iocb->ki_filp->f_mapping; + size_t write_len =3D iov_iter_count(from); + ssize_t written; =20 /* * If a page can not be invalidated, return 0 to fall back @@ -3772,7 +3776,7 @@ generic_file_direct_write(struct kiocb *iocb, struct = iov_iter *from) if (written) { if (written =3D=3D -EBUSY) return 0; - goto out; + return written; } =20 written =3D mapping->a_ops->direct_IO(iocb, from); @@ -3794,11 +3798,11 @@ generic_file_direct_write(struct kiocb *iocb, struc= t iov_iter *from) * * Skip invalidation for async writes or if mapping has no pages. */ - if (written > 0 && mapping->nrpages && - invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT, end)) - dio_warn_stale_pagecache(file); - if (written > 0) { + struct inode *inode =3D mapping->host; + loff_t pos =3D iocb->ki_pos; + + kiocb_invalidate_post_direct_write(iocb, written); pos +=3D written; write_len -=3D written; if (pos > i_size_read(inode) && !S_ISBLK(inode->i_mode)) { @@ -3809,7 +3813,6 @@ generic_file_direct_write(struct kiocb *iocb, struct = iov_iter *from) } if (written !=3D -EIOCBQUEUED) iov_iter_revert(from, write_len - iov_iter_count(from)); -out: return written; } EXPORT_SYMBOL(generic_file_direct_write); --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com [52.28.197.132]) (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 8E80D27F005; Tue, 21 Oct 2025 07:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=52.28.197.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030644; cv=none; b=rhjr8SfJQ4LIMS6sB36jGrRtloqZhrH4tbTnsPuioZZ5Qu/vFRXKaoZTyMEpnqw0JHrskpJR/n8nnEVAYeuRTAQyUQXU4rkcZMnzM3/jAoCXAPcjYnfw9i9hrjl1TuCz7IK5q2ZUk6PlhkT3rRI7UJ3y4umE5t3d0IByij6TD6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030644; c=relaxed/simple; bh=+tk/FutCRm8YcGzprGsostpgdVHh9u+7caB92/41LIQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BbKXTHO0gifUFUOzOG9+PPXOpYKn4PKaGWl2y1g2j9cmgea/1XSmrH1wUF9UJu7YG2o4vPsVU73wfqvDBrlsrZunHiIAL0+urmEBo4u6IUnwbaJryrdw8a72EyIzOSLqkFv067JSdG9UwmbKSBxduHC5nvYAu9KmFRR4xw00lPQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=lCH5OWQK; arc=none smtp.client-ip=52.28.197.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="lCH5OWQK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030642; x=1792566642; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=HA9qae2hxkl8hOt3UHdMdc2bodJDRIauUiWzAAKxlsQ=; b=lCH5OWQK7H6goS/t75kWaW21hXndHOlULq3510V9bnnh9FiPqafo//Kv 01ZrrhtfuOpI/0hV0vPP2432tGMw021YU1ULklT/T2yVjXprPEAWnmyum J9ns06hvJRkCQBQ0vK+A+Z5dLov90fJxZNkl43gD0yMHV8WOaVgDeKFpp Fi4v3Rh3QfMuW8CxqxQvDTq+pMFrv5HWV4aW+7Qzg/0YvAhMNP38sjix6 4aW2jEvzPZtd6J5KedxTCig8fXf/zZZadJ8pVM3+LeXAhlf+EU+H1DLgU 1d1nJ4EokJUZ04Gnx3vVk7FQy/L4v3COH0+jUX9n4ctZcCRciDW8tu+8t Q==; X-CSE-ConnectionGUID: jh51iiDKQJqIacjSQTTaqQ== X-CSE-MsgGUID: fUMgNCHbQ2Gy7BekZqIj0g== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3831851" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-011.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:10:31 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:19308] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.38.159:2525] with esmtp (Farcaster) id 76ee5b86-eab3-4d96-a848-ee94f9729fd2; Tue, 21 Oct 2025 07:10:30 +0000 (UTC) X-Farcaster-Flow-ID: 76ee5b86-eab3-4d96-a848-ee94f9729fd2 Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:10:29 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:10:18 +0000 From: Mahmoud Adam To: CC: , , Christoph Hellwig , Xiubo Li , Damien Le Moal , Hannes Reinecke , Theodore Ts'o , "Darrick J. Wong" , Al Viro , Andreas Gruenbacher , "Anna Schumaker" , Chao Yu , Christian Brauner , Ilya Dryomov , Jaegeuk Kim , Jens Axboe , Johannes Thumshirn , Matthew Wilcox , "Miklos Szeredi" , Miklos Szeredi , "Trond Myklebust" , Andrew Morton , Jeff Layton , Andreas Dilger , Christoph Hellwig , "Ryusuke Konishi" , Luis Chamberlain , , , , , , , , , , Subject: [PATCH 6.1 3/8] filemap: update ki_pos in generic_perform_write Date: Tue, 21 Oct 2025 09:03:38 +0200 Message-ID: <20251021070353.96705-5-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D036UWC002.ant.amazon.com (10.13.139.242) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christoph Hellwig commit 182c25e9c157f37bd0ab5a82fe2417e2223df459 upstream. All callers of generic_perform_write need to updated ki_pos, move it into common code. Link: https://lkml.kernel.org/r/20230601145904.1385409-4-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Xiubo Li Reviewed-by: Damien Le Moal Reviewed-by: Hannes Reinecke Acked-by: Theodore Ts'o Acked-by: Darrick J. Wong Cc: Al Viro Cc: Andreas Gruenbacher Cc: Anna Schumaker Cc: Chao Yu Cc: Christian Brauner Cc: Ilya Dryomov Cc: Jaegeuk Kim Cc: Jens Axboe Cc: Johannes Thumshirn Cc: Matthew Wilcox Cc: Miklos Szeredi Cc: Miklos Szeredi Cc: Trond Myklebust Signed-off-by: Andrew Morton Signed-off-by: Mahmoud Adam --- fs/ceph/file.c | 2 -- fs/ext4/file.c | 9 +++------ fs/f2fs/file.c | 1 - fs/nfs/file.c | 1 - mm/filemap.c | 8 ++++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 3336647e64df3a..5921bf278fff72 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1891,8 +1891,6 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, st= ruct iov_iter *from) * can not run at the same time */ written =3D generic_perform_write(iocb, from); - if (likely(written >=3D 0)) - iocb->ki_pos =3D pos + written; ceph_end_io_write(inode); } =20 diff --git a/fs/ext4/file.c b/fs/ext4/file.c index 289b088f4ae58f..e84a144f3f8ed5 100644 --- a/fs/ext4/file.c +++ b/fs/ext4/file.c @@ -287,12 +287,9 @@ static ssize_t ext4_buffered_write_iter(struct kiocb *= iocb, =20 out: inode_unlock(inode); - if (likely(ret > 0)) { - iocb->ki_pos +=3D ret; - ret =3D generic_write_sync(iocb, ret); - } - - return ret; + if (unlikely(ret <=3D 0)) + return ret; + return generic_write_sync(iocb, ret); } =20 static ssize_t ext4_handle_inode_extension(struct inode *inode, loff_t off= set, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 5e2a0cb8d24d92..09b85d086d16a6 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4661,7 +4661,6 @@ static ssize_t f2fs_buffered_write_iter(struct kiocb = *iocb, current->backing_dev_info =3D NULL; =20 if (ret > 0) { - iocb->ki_pos +=3D ret; f2fs_update_iostat(F2FS_I_SB(inode), inode, APP_BUFFERED_IO, ret); } diff --git a/fs/nfs/file.c b/fs/nfs/file.c index d8ec889a4b3f76..c1be636ef25729 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -645,7 +645,6 @@ ssize_t nfs_file_write(struct kiocb *iocb, struct iov_i= ter *from) goto out; =20 written =3D result; - iocb->ki_pos +=3D written; nfs_add_stats(inode, NFSIOS_NORMALWRITTENBYTES, written); =20 if (mntflags & NFS_MOUNT_WRITE_EAGER) { diff --git a/mm/filemap.c b/mm/filemap.c index 39484af4300e3c..e2045266d2f2c9 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3891,7 +3891,10 @@ ssize_t generic_perform_write(struct kiocb *iocb, st= ruct iov_iter *i) balance_dirty_pages_ratelimited(mapping); } while (iov_iter_count(i)); =20 - return written ? written : status; + if (!written) + return status; + iocb->ki_pos +=3D written; + return written; } EXPORT_SYMBOL(generic_perform_write); =20 @@ -3970,7 +3973,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb,= struct iov_iter *from) endbyte =3D pos + status - 1; err =3D filemap_write_and_wait_range(mapping, pos, endbyte); if (err =3D=3D 0) { - iocb->ki_pos =3D endbyte + 1; written +=3D status; invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, @@ -3983,8 +3985,6 @@ ssize_t __generic_file_write_iter(struct kiocb *iocb,= struct iov_iter *from) } } else { written =3D generic_perform_write(iocb, from); - if (likely(written > 0)) - iocb->ki_pos +=3D written; } out: current->backing_dev_info =3D NULL; --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-001.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-001.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.156.205.64]) (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 A49F7227E83; Tue, 21 Oct 2025 07:11:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.156.205.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030675; cv=none; b=HZrfidmMLCRUmV/EYjfcS8Nsx6ueg3XOT/UIm0eWnXyA2SA91gPxuNJhzaTEtyUentPgWqgcLBJtTi1ifEBcd2UHhEH6j6XeBKTIpNPO1d422lzj8m6sgyCp2MJjdSLOBU1V+wr7fbWVrirbxz5qjkvgzQczWXUE00ezoPZP7Kw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030675; c=relaxed/simple; bh=NedYjdt3harctfQHy2LxknH3Up6TsR4kfMruhCy+Qhw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DWFvMEsuOYxk+wrJPIIuZSvsuRrQ3377iu7MJFqu6BG2sVw1ZkgjFL8PEaVG2OVqVtHvROtKSp8Zfdjq2XuPUz3yWw3f4Dh8UZjB1DHlLF7YqT4eMlFSmgb7YbsocLVN2A/O4yx9OustFix84A6IPAJD7CgkH/ja9tU504ydDnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=rQJv4+T5; arc=none smtp.client-ip=18.156.205.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="rQJv4+T5" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030673; x=1792566673; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EWT2gm3mr1yTWppm7hvARyuErTtEe+bWsoFO42B5tnI=; b=rQJv4+T5EupMGoyFYEesF8+/V+dC8ClJggBStXH2vNXzu3URTi577vG3 SiuGAIMFAozfFfyM7ifbIVKlCxV+ie2eJJjhxN/f4IVwjea6nSDe0YPy1 +0pSr7hr9YKN9U0DAblQ7Oi8xgiColtPvs3ZCNV1ntQikpfCIpnGhsY/j WhZkAhf5tKGqRR96O7Igz3DPh54S1+gz0x71JSNjT1M4Oa1YVCnWNjDel wyv8nS4gny9qU7eSn0Br9GYXxLrxw8qvpPu7GS62UPF4k6RdfdLuP0QFu NNC6zh5eg1sTRYNtAg+NBmI5pR7EL9EVBG+Bkl7s94zK6Yub93OkShClY w==; X-CSE-ConnectionGUID: DKfSEOkqQQKB8ERoq7WY2A== X-CSE-MsgGUID: DEt+B/AnQgG5Vzyn9KIMpA== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3933276" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-001.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:10:59 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:11521] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.29.7:2525] with esmtp (Farcaster) id 72943488-d8d8-46a1-a014-aaf1f5c61ddd; Tue, 21 Oct 2025 07:10:59 +0000 (UTC) X-Farcaster-Flow-ID: 72943488-d8d8-46a1-a014-aaf1f5c61ddd Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:10:59 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:10:48 +0000 From: Mahmoud Adam To: CC: , , Christoph Hellwig , Damien Le Moal , Miklos Szeredi , "Darrick J. Wong" , Al Viro , Andreas Gruenbacher , "Anna Schumaker" , Chao Yu , Christian Brauner , Hannes Reinecke , Ilya Dryomov , Jaegeuk Kim , Jens Axboe , Johannes Thumshirn , "Matthew Wilcox" , Miklos Szeredi , "Theodore Ts'o" , Trond Myklebust , Xiubo Li , Andrew Morton , "Jeff Layton" , Andreas Dilger , Christoph Hellwig , Ryusuke Konishi , Luis Chamberlain , , , , , , , , , , Subject: [PATCH 6.1 4/8] fs: factor out a direct_write_fallback helper Date: Tue, 21 Oct 2025 09:03:39 +0200 Message-ID: <20251021070353.96705-6-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D038UWB002.ant.amazon.com (10.13.139.185) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christoph Hellwig commit 44fff0fa08ec5a6d9d5fb05443a36d854d0ece4d upstream. Add a helper dealing with handling the syncing of a buffered write fallback for direct I/O. Link: https://lkml.kernel.org/r/20230601145904.1385409-10-hch@lst.de Signed-off-by: Christoph Hellwig Reviewed-by: Damien Le Moal Reviewed-by: Miklos Szeredi Reviewed-by: Darrick J. Wong Cc: Al Viro Cc: Andreas Gruenbacher Cc: Anna Schumaker Cc: Chao Yu Cc: Christian Brauner Cc: Hannes Reinecke Cc: Ilya Dryomov Cc: Jaegeuk Kim Cc: Jens Axboe Cc: Johannes Thumshirn Cc: Matthew Wilcox Cc: Miklos Szeredi Cc: Theodore Ts'o Cc: Trond Myklebust Cc: Xiubo Li Signed-off-by: Andrew Morton [backing_dev_info still being used here. do small changes to the patch to keep the out label. Which means replacing all returns to goto out.] Signed-off-by: Mahmoud Adam --- fs/libfs.c | 41 +++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ mm/filemap.c | 61 +++++++++++----------------------------------- 3 files changed, 57 insertions(+), 47 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index cbd42d76fbd018..a5bbe8e31d6616 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1582,3 +1582,44 @@ bool inode_maybe_inc_iversion(struct inode *inode, b= ool force) return true; } EXPORT_SYMBOL(inode_maybe_inc_iversion); + +ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, + ssize_t direct_written, ssize_t buffered_written) +{ + struct address_space *mapping =3D iocb->ki_filp->f_mapping; + loff_t pos =3D iocb->ki_pos - buffered_written; + loff_t end =3D iocb->ki_pos - 1; + int err; + + /* + * If the buffered write fallback returned an error, we want to return + * the number of bytes which were written by direct I/O, or the error + * code if that was zero. + * + * Note that this differs from normal direct-io semantics, which will + * return -EFOO even if some bytes were written. + */ + if (unlikely(buffered_written < 0)) { + if (direct_written) + return direct_written; + return buffered_written; + } + + /* + * We need to ensure that the page cache pages are written to disk and + * invalidated to preserve the expected O_DIRECT semantics. + */ + err =3D filemap_write_and_wait_range(mapping, pos, end); + if (err < 0) { + /* + * We don't know how much we wrote, so just return the number of + * bytes which were direct-written + */ + if (direct_written) + return direct_written; + return err; + } + invalidate_mapping_pages(mapping, pos >> PAGE_SHIFT, end >> PAGE_SHIFT); + return direct_written + buffered_written; +} +EXPORT_SYMBOL_GPL(direct_write_fallback); diff --git a/include/linux/fs.h b/include/linux/fs.h index 4e8a3e4f894c0f..02c83cd07d4f20 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3278,6 +3278,8 @@ extern ssize_t __generic_file_write_iter(struct kiocb= *, struct iov_iter *); extern ssize_t generic_file_write_iter(struct kiocb *, struct iov_iter *); extern ssize_t generic_file_direct_write(struct kiocb *, struct iov_iter *= ); ssize_t generic_perform_write(struct kiocb *, struct iov_iter *); +ssize_t direct_write_fallback(struct kiocb *iocb, struct iov_iter *iter, + ssize_t direct_written, ssize_t buffered_written); =20 ssize_t vfs_iter_read(struct file *file, struct iov_iter *iter, loff_t *pp= os, rwf_t flags); diff --git a/mm/filemap.c b/mm/filemap.c index e2045266d2f2c9..b77f534dfad35a 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -3923,25 +3923,21 @@ ssize_t __generic_file_write_iter(struct kiocb *ioc= b, struct iov_iter *from) { struct file *file =3D iocb->ki_filp; struct address_space *mapping =3D file->f_mapping; - struct inode *inode =3D mapping->host; - ssize_t written =3D 0; - ssize_t err; - ssize_t status; + struct inode *inode =3D mapping->host; + ssize_t ret; =20 /* We can write back this queue in page reclaim */ current->backing_dev_info =3D inode_to_bdi(inode); - err =3D file_remove_privs(file); - if (err) + ret =3D file_remove_privs(file); + if (ret) goto out; =20 - err =3D file_update_time(file); - if (err) + ret =3D file_update_time(file); + if (ret) goto out; =20 if (iocb->ki_flags & IOCB_DIRECT) { - loff_t pos, endbyte; - - written =3D generic_file_direct_write(iocb, from); + ret =3D generic_file_direct_write(iocb, from); /* * If the write stopped short of completing, fall back to * buffered writes. Some filesystems do this for writes to @@ -3949,46 +3945,17 @@ ssize_t __generic_file_write_iter(struct kiocb *ioc= b, struct iov_iter *from) * not succeed (even if it did, DAX does not handle dirty * page-cache pages correctly). */ - if (written < 0 || !iov_iter_count(from) || IS_DAX(inode)) + if (ret < 0 || !iov_iter_count(from) || IS_DAX(inode)) goto out; - - pos =3D iocb->ki_pos; - status =3D generic_perform_write(iocb, from); - /* - * If generic_perform_write() returned a synchronous error - * then we want to return the number of bytes which were - * direct-written, or the error code if that was zero. Note - * that this differs from normal direct-io semantics, which - * will return -EFOO even if some bytes were written. - */ - if (unlikely(status < 0)) { - err =3D status; - goto out; - } - /* - * We need to ensure that the page cache pages are written to - * disk and invalidated to preserve the expected O_DIRECT - * semantics. - */ - endbyte =3D pos + status - 1; - err =3D filemap_write_and_wait_range(mapping, pos, endbyte); - if (err =3D=3D 0) { - written +=3D status; - invalidate_mapping_pages(mapping, - pos >> PAGE_SHIFT, - endbyte >> PAGE_SHIFT); - } else { - /* - * We don't know how much we wrote, so just return - * the number of bytes which were direct-written - */ - } - } else { - written =3D generic_perform_write(iocb, from); + ret =3D direct_write_fallback(iocb, from, ret, + generic_perform_write(iocb, from)); + goto out; } + + ret =3D generic_perform_write(iocb, from); out: current->backing_dev_info =3D NULL; - return written ? written : err; + return ret; } EXPORT_SYMBOL(__generic_file_write_iter); =20 --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.199.210.3]) (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 5DA5D2737F8; Tue, 21 Oct 2025 07:11:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.199.210.3 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030704; cv=none; b=sHO/tnoF4i+WLKtkjneOtjFNMpTEP6m+M5mzDlochydN/wwnRkrftUzJ4LMLdEq6aJlC729RBXWN3DrWLH2qpco2MvYPjibg6S0UB7/Po6gzzUYoU8jKzVRROwMw0nlFx0+5lKyiPKlRixHDFQnfO24/JTWA5ro7E2cMjG21WcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030704; c=relaxed/simple; bh=aS75Pmkr7ko5nrziWGIpkCaBU+bk1gMXDCjKi2pXjwc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HnC35eojtI1CQMv/zQvcJWtaVXeFAjiJFbqHbtlUwvTUKLmFccmgmUtEWW39PzFtrQWOvA8H7wPHIv5l3sHO/V077IG6isihiFREi75U2D0ZWTprik7ojqN9u3oDzRZeO266/hRbS6jDZWGknOYqcHHf8o5SM6FIBzzl+c5hCTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=a/cBIgJ3; arc=none smtp.client-ip=18.199.210.3 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="a/cBIgJ3" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030702; x=1792566702; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ER5cLgoC/4MdsBzdzUsBYBpn6poQFnbZbMEZNMZv5Vc=; b=a/cBIgJ3MTHuUdptKGjOpwVuAaXNjevyQzET7dHW1d7aMXrCofRxJsBb KVt61Z2+S+iWWg/ShZdxkwjVrPDmu8ctPAxXPK9oDt2myjWYS7D6VQYX1 fI6MF4eQXBg30SauHLzg1ORoHPxdX+Q37Zkx5HYu4ibrvs1DWWnSePGbo 6HpZv7w16D3N/Q1ElsKxvf/HVuMvp2UDFHY1IBo1CI1zKpD4F7PJprp7v glNR254YiE24Cd8PON3/T89Dc7EEy2OuGXLcrSrMiqETyOUSqgdQuckEo EMQPx7Nd+d3iBv/3H5YF/r/WrtQcJ6JYqv7KELFghFIbjzMe992kcDdM1 w==; X-CSE-ConnectionGUID: kUEZ2KC2Rfa44N6E7Rqgsw== X-CSE-MsgGUID: epsBYkLXTYGjTRt8EkVXCA== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3824996" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-014.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:11:29 +0000 Received: from EX19MTAEUC001.ant.amazon.com [54.240.197.225:28509] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.18.241:2525] with esmtp (Farcaster) id c31f0d4e-9a33-4d49-91df-70df47201fd2; Tue, 21 Oct 2025 07:11:28 +0000 (UTC) X-Farcaster-Flow-ID: c31f0d4e-9a33-4d49-91df-70df47201fd2 Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUC001.ant.amazon.com (10.252.51.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:11:28 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:11:19 +0000 From: Mahmoud Adam To: CC: , , Al Viro , Christian Brauner , Jens Axboe , Xiubo Li , Ilya Dryomov , Jeff Layton , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , "Ryusuke Konishi" , "Matthew Wilcox (Oracle)" , Andrew Morton , "Hannes Reinecke" , Damien Le Moal , "Luis Chamberlain" , , , , , , , , , , Subject: [PATCH 6.1 5/8] direct_write_fallback(): on error revert the ->ki_pos update from buffered write Date: Tue, 21 Oct 2025 09:03:40 +0200 Message-ID: <20251021070353.96705-7-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D046UWB003.ant.amazon.com (10.13.139.174) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Al Viro commit 8287474aa5ffb41df52552c4ae4748e791d2faf2 upstream. If we fail filemap_write_and_wait_range() on the range the buffered write w= ent into, we only report the "number of bytes which we direct-written", to quote the comment in there. Which is fine, but buffered write has already advanc= ed iocb->ki_pos, so we need to roll that back. Otherwise we end up with e.g. write(2) advancing position by more than the amount it reports having writt= en. Fixes: 182c25e9c157 "filemap: update ki_pos in generic_perform_write" Signed-off-by: Al Viro Message-Id: <20230827214518.GU3390869@ZenIV> Signed-off-by: Christian Brauner Signed-off-by: Mahmoud Adam --- fs/libfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/libfs.c b/fs/libfs.c index a5bbe8e31d6616..63bc52c20f7e03 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1615,6 +1615,7 @@ ssize_t direct_write_fallback(struct kiocb *iocb, str= uct iov_iter *iter, * We don't know how much we wrote, so just return the number of * bytes which were direct-written */ + iocb->ki_pos -=3D buffered_written; if (direct_written) return direct_written; return err; --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com [63.178.132.221]) (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 165D5354AC9; Tue, 21 Oct 2025 07:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=63.178.132.221 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030731; cv=none; b=dIAw8gwaG4ym/vHL4uaSDexlUtOAjYlq+zq5tcwSehVAD9lGwCLPJGUTyxe6z9dmu4i7hiVDG0/GZA64NP0KXphypfyCxI6JumVIOjbyvxdgPI2CP8GUvC1cF/NH7KeyOINm8qAfVHJArn9umxNGfwthvIogC5NQV+3qg2utYa8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030731; c=relaxed/simple; bh=qBXMD7foKCLM8tG99NVLnc1+8+/Ddg/uvu+Ww3sKHXE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=h/GGXAMB1QjJe56WB5XBJi0OnZ54huh2RwbbSbsrhwNq1igax6HXVO2cG+OmFKRjrVjDpdgSX+i4NIW3pvADItrOu/ux3Om05Jt4VjNVZbuk6G3pA4h35om9hfwXkThsRFlvVtykbGnMsHTYVnsqdCmBTFORR+mIaM0+E0HlhDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=ajEmScFX; arc=none smtp.client-ip=63.178.132.221 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="ajEmScFX" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030729; x=1792566729; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xox3qTc8hYU6L3c6JXOuETVCy0yWRIpRqh99YwnzkOo=; b=ajEmScFX9+HXP8f9AuavN6luknZYMPv2RTENAhOHWSP6AyDzJwAZ8wxY slyWfeSyByw1EjRmuHQVCzJdvq5yiJijjVrCRzFMNFOrLdj8iOuKRP4V+ 8f2LUDJ6p+F0c3HVbTChbv8SSJSxjliNEmcs74zqcPWkei/9EvQ9/+cAE MMh8TFeZxoWIbGGtqJuaqJfkjsyXaTfZSUv5JfiCIesRarywCGKzR9Djw DPnwqpDj1GuRMKbU2yXzpOpohSzONvR3z6yshg6QTV+Fv2wNQwXYN084C lZDtEzAWDjNO33p6bwbjXhkQ4sRZr/XmAvt3b0bIVIH+/gdQ0Ght7poIU A==; X-CSE-ConnectionGUID: 6VGIvb/dQ++kJKWLFnmwYA== X-CSE-MsgGUID: OwKsQXoZQsikLSKYYlhXrA== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3828837" Received: from ip-10-6-11-83.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.11.83]) by internal-fra-out-013.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:11:57 +0000 Received: from EX19MTAEUA002.ant.amazon.com [54.240.197.232:11098] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.17.8:2525] with esmtp (Farcaster) id 6cec1b60-3232-473d-9f64-4d0e631f5a13; Tue, 21 Oct 2025 07:11:57 +0000 (UTC) X-Farcaster-Flow-ID: 6cec1b60-3232-473d-9f64-4d0e631f5a13 Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUA002.ant.amazon.com (10.252.50.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:11:57 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:11:48 +0000 From: Mahmoud Adam To: CC: , , Christoph Hellwig , Johannes Thumshirn , "Christian Brauner" , Hannes Reinecke , "Luis Chamberlain" , Jens Axboe , Xiubo Li , Ilya Dryomov , Jeff Layton , Alexander Viro , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , "Ryusuke Konishi" , "Matthew Wilcox (Oracle)" , Andrew Morton , "Damien Le Moal" , , , , , , , , , , Subject: [PATCH 6.1 6/8] block: open code __generic_file_write_iter for blkdev writes Date: Tue, 21 Oct 2025 09:03:41 +0200 Message-ID: <20251021070353.96705-8-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D045UWA003.ant.amazon.com (10.13.139.46) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Christoph Hellwig commit 727cfe976758b79f8d2f8051c75a5ccb14539a56 upstream. Open code __generic_file_write_iter to remove the indirect call into ->direct_IO and to prepare using the iomap based write code. Signed-off-by: Christoph Hellwig Reviewed-by: Johannes Thumshirn Reviewed-by: Christian Brauner Reviewed-by: Hannes Reinecke Reviewed-by: Luis Chamberlain Link: https://lore.kernel.org/r/20230801172201.1923299-4-hch@lst.de Signed-off-by: Jens Axboe [fix contextual changes] Signed-off-by: Mahmoud Adam --- block/fops.c | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/block/fops.c b/block/fops.c index b02fe200c3ecd0..fb7a57ed42d995 100644 --- a/block/fops.c +++ b/block/fops.c @@ -515,6 +515,30 @@ static int blkdev_close(struct inode *inode, struct fi= le *filp) return 0; } =20 +static ssize_t +blkdev_direct_write(struct kiocb *iocb, struct iov_iter *from) +{ + size_t count =3D iov_iter_count(from); + ssize_t written; + + written =3D kiocb_invalidate_pages(iocb, count); + if (written) { + if (written =3D=3D -EBUSY) + return 0; + return written; + } + + written =3D blkdev_direct_IO(iocb, from); + if (written > 0) { + kiocb_invalidate_post_direct_write(iocb, count); + iocb->ki_pos +=3D written; + count -=3D written; + } + if (written !=3D -EIOCBQUEUED) + iov_iter_revert(from, count - iov_iter_count(from)); + return written; +} + /* * Write data to the block device. Only intended for the block device its= elf * and the raw driver which basically is a fake block device. @@ -524,7 +548,8 @@ static int blkdev_close(struct inode *inode, struct fil= e *filp) */ static ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) { - struct block_device *bdev =3D iocb->ki_filp->private_data; + struct file *file =3D iocb->ki_filp; + struct block_device *bdev =3D file->private_data; struct inode *bd_inode =3D bdev->bd_inode; loff_t size =3D bdev_nr_bytes(bdev); struct blk_plug plug; @@ -553,7 +578,23 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, s= truct iov_iter *from) } =20 blk_start_plug(&plug); - ret =3D __generic_file_write_iter(iocb, from); + ret =3D file_remove_privs(file); + if (ret) + return ret; + + ret =3D file_update_time(file); + if (ret) + return ret; + + if (iocb->ki_flags & IOCB_DIRECT) { + ret =3D blkdev_direct_write(iocb, from); + if (ret >=3D 0 && iov_iter_count(from)) + ret =3D direct_write_fallback(iocb, from, ret, + generic_perform_write(iocb, from)); + } else { + ret =3D generic_perform_write(iocb, from); + } + if (ret > 0) ret =3D generic_write_sync(iocb, ret); iov_iter_reexpand(from, iov_iter_count(from) + shorted); --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com [18.197.217.180]) (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 83DFD275861; Tue, 21 Oct 2025 07:12:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=18.197.217.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030761; cv=none; b=r/NoW9SqFbRAThs5SqH8ZslmarX77+B0NaCS6zgdH6L31sR9UXRwDrH0b94cPeF34xBfTcwTt7r46qnStpObTpCCpbgxvIqkhhrhlFQoSYrZaEe0F5XSIoElpRiVIkZ54+x3pFudUma3oyJSYQcxcYXmUcxmUEzfSU/L2AJJn+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030761; c=relaxed/simple; bh=XoZh3t7IeR1HA8mtNWmkCL17O8IJQtXuDyY4LMiV7SU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OlWH7yqxT7gIfhurbo23HO/DvyNJcTmMeLyeINXHxft7pWQMeL52IAevWMmzqKQo0pVkOW9H1jiC9ASdqbI2nECGZv3y/S6jvMdT86EgNoYgWAqVmZrKMu3Bs47rxX6qfntDsu+hpx82ZNMeXo2oq3VLGtltQwNKUvaZ4DEorpM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=IBUDDyad; arc=none smtp.client-ip=18.197.217.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="IBUDDyad" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030758; x=1792566758; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XbsklnLadu0TimGCGccN0DzgzObfA2bbC0YKqZmM7XE=; b=IBUDDyadU5YDvy7zdqApSnUXb/LnL6tbfCs53RpphhKqSMRZU46DrNRn EFpEQrS5BLxfpGh81aDydswMz0x3A1nCJ+uDAzHeEkwXfxfrbezSxpsDZ Gt4CcbPuSgUpkIThSmgT4mZtezXFc5evCYNhZEjpVG+t5ZOuDwIdAFH1J ygcSByJ8IfBZFGo3EZfIcNrntP/Zwjv3SxxOpzguhgkCNuBQAYj/vdv9I j7Xpw5exazrDtnNjH4id4YFfiQ1nHhWFSz8OJVEpKjXDb+eU2MUDA7Qk3 p1Om2w9EP0smGC9CU11xfYWjHQbmHIGhlivLvnpsxc1pg3NKiNm5zryPY w==; X-CSE-ConnectionGUID: eoJi007nQRij3hX+bGiZxw== X-CSE-MsgGUID: vEwiZ/SEQsSkyB5yOtxRcg== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3930984" Received: from ip-10-6-6-97.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.6.97]) by internal-fra-out-006.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:12:27 +0000 Received: from EX19MTAEUB001.ant.amazon.com [54.240.197.234:21179] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.15.203:2525] with esmtp (Farcaster) id 3389bf29-a6fa-4def-bde8-26368f7ce873; Tue, 21 Oct 2025 07:12:27 +0000 (UTC) X-Farcaster-Flow-ID: 3389bf29-a6fa-4def-bde8-26368f7ce873 Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUB001.ant.amazon.com (10.252.51.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:12:26 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:12:17 +0000 From: Mahmoud Adam To: CC: , , "Darrick J. Wong" , Christoph Hellwig , Luis Chamberlain , Shin'ichiro Kawasaki , "Jens Axboe" , Xiubo Li , Ilya Dryomov , Jeff Layton , Alexander Viro , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig , Trond Myklebust , Anna Schumaker , "Ryusuke Konishi" , "Matthew Wilcox (Oracle)" , Andrew Morton , "Hannes Reinecke" , Damien Le Moal , , , , , , , , , , Subject: [PATCH 6.1 7/8] block: fix race between set_blocksize and read paths Date: Tue, 21 Oct 2025 09:03:42 +0200 Message-ID: <20251021070353.96705-9-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D042UWB003.ant.amazon.com (10.13.139.135) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Darrick J. Wong" commit c0e473a0d226479e8e925d5ba93f751d8df628e9 upstream. With the new large sector size support, it's now the case that set_blocksize can change i_blksize and the folio order in a manner that conflicts with a concurrent reader and causes a kernel crash. Specifically, let's say that udev-worker calls libblkid to detect the labels on a block device. The read call can create an order-0 folio to read the first 4096 bytes from the disk. But then udev is preempted. Next, someone tries to mount an 8k-sectorsize filesystem from the same block device. The filesystem calls set_blksize, which sets i_blksize to 8192 and the minimum folio order to 1. Now udev resumes, still holding the order-0 folio it allocated. It then tries to schedule a read bio and do_mpage_readahead tries to create bufferheads for the folio. Unfortunately, blocks_per_folio =3D=3D 0 because the page size is 4096 but the blocksize is 8192 so no bufferheads are attached and the bh walk never sets bdev. We then submit the bio with a NULL block device and crash. Therefore, truncate the page cache after flushing but before updating i_blksize. However, that's not enough -- we also need to lock out file IO and page faults during the update. Take both the i_rwsem and the invalidate_lock in exclusive mode for invalidations, and in shared mode for read/write operations. I don't know if this is the correct fix, but xfs/259 found it. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig Reviewed-by: Luis Chamberlain Tested-by: Shin'ichiro Kawasaki Link: https://lore.kernel.org/r/174543795699.4139148.2086129139322431423.st= git@frogsfrogsfrogs Signed-off-by: Jens Axboe [use bdev->bd_inode instead & fix small contextual changes] Signed-off-by: Mahmoud Adam --- block/bdev.c | 17 +++++++++++++++++ block/blk-zoned.c | 5 ++++- block/fops.c | 16 ++++++++++++++++ block/ioctl.c | 6 ++++++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/block/bdev.c b/block/bdev.c index b61502ec8da06c..5a631a0ca46a81 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -147,9 +147,26 @@ int set_blocksize(struct block_device *bdev, int size) =20 /* Don't change the size if it is same as current */ if (bdev->bd_inode->i_blkbits !=3D blksize_bits(size)) { + /* + * Flush and truncate the pagecache before we reconfigure the + * mapping geometry because folio sizes are variable now. If a + * reader has already allocated a folio whose size is smaller + * than the new min_order but invokes readahead after the new + * min_order becomes visible, readahead will think there are + * "zero" blocks per folio and crash. Take the inode and + * invalidation locks to avoid racing with + * read/write/fallocate. + */ + inode_lock(bdev->bd_inode); + filemap_invalidate_lock(bdev->bd_inode->i_mapping); + sync_blockdev(bdev); + kill_bdev(bdev); + bdev->bd_inode->i_blkbits =3D blksize_bits(size); kill_bdev(bdev); + filemap_invalidate_unlock(bdev->bd_inode->i_mapping); + inode_unlock(bdev->bd_inode); } return 0; } diff --git a/block/blk-zoned.c b/block/blk-zoned.c index db829401d8d0ca..ef72612ca4645f 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -417,6 +417,7 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, f= mode_t mode, op =3D REQ_OP_ZONE_RESET; =20 /* Invalidate the page cache, including dirty pages. */ + inode_lock(bdev->bd_inode); filemap_invalidate_lock(bdev->bd_inode->i_mapping); ret =3D blkdev_truncate_zone_range(bdev, mode, &zrange); if (ret) @@ -439,8 +440,10 @@ int blkdev_zone_mgmt_ioctl(struct block_device *bdev, = fmode_t mode, GFP_KERNEL); =20 fail: - if (cmd =3D=3D BLKRESETZONE) + if (cmd =3D=3D BLKRESETZONE) { filemap_invalidate_unlock(bdev->bd_inode->i_mapping); + inode_unlock(bdev->bd_inode); + } =20 return ret; } diff --git a/block/fops.c b/block/fops.c index fb7a57ed42d995..2fc6ac6679ee63 100644 --- a/block/fops.c +++ b/block/fops.c @@ -592,7 +592,14 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, s= truct iov_iter *from) ret =3D direct_write_fallback(iocb, from, ret, generic_perform_write(iocb, from)); } else { + /* + * Take i_rwsem and invalidate_lock to avoid racing with + * set_blocksize changing i_blkbits/folio order and punching + * out the pagecache. + */ + inode_lock_shared(bd_inode); ret =3D generic_perform_write(iocb, from); + inode_unlock_shared(bd_inode); } =20 if (ret > 0) @@ -605,6 +612,7 @@ static ssize_t blkdev_write_iter(struct kiocb *iocb, st= ruct iov_iter *from) static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to) { struct block_device *bdev =3D iocb->ki_filp->private_data; + struct inode *bd_inode =3D bdev->bd_inode; loff_t size =3D bdev_nr_bytes(bdev); loff_t pos =3D iocb->ki_pos; size_t shorted =3D 0; @@ -652,7 +660,13 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, st= ruct iov_iter *to) goto reexpand; } =20 + /* + * Take i_rwsem and invalidate_lock to avoid racing with set_blocksize + * changing i_blkbits/folio order and punching out the pagecache. + */ + inode_lock_shared(bd_inode); ret =3D filemap_read(iocb, to, ret); + inode_unlock_shared(bd_inode); =20 reexpand: if (unlikely(shorted)) @@ -695,6 +709,7 @@ static long blkdev_fallocate(struct file *file, int mod= e, loff_t start, if ((start | len) & (bdev_logical_block_size(bdev) - 1)) return -EINVAL; =20 + inode_lock(inode); filemap_invalidate_lock(inode->i_mapping); =20 /* @@ -735,6 +750,7 @@ static long blkdev_fallocate(struct file *file, int mod= e, loff_t start, =20 fail: filemap_invalidate_unlock(inode->i_mapping); + inode_unlock(inode); return error; } =20 diff --git a/block/ioctl.c b/block/ioctl.c index 552da0ccbec09e..b37bbe9b3487d8 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -114,6 +114,7 @@ static int blk_ioctl_discard(struct block_device *bdev,= fmode_t mode, end > bdev_nr_bytes(bdev)) return -EINVAL; =20 + inode_lock(inode); filemap_invalidate_lock(inode->i_mapping); err =3D truncate_bdev_range(bdev, mode, start, end - 1); if (err) @@ -121,6 +122,7 @@ static int blk_ioctl_discard(struct block_device *bdev,= fmode_t mode, err =3D blkdev_issue_discard(bdev, start >> 9, len >> 9, GFP_KERNEL); fail: filemap_invalidate_unlock(inode->i_mapping); + inode_unlock(inode); return err; } =20 @@ -146,12 +148,14 @@ static int blk_ioctl_secure_erase(struct block_device= *bdev, fmode_t mode, end > bdev_nr_bytes(bdev)) return -EINVAL; =20 + inode_lock(bdev->bd_inode); filemap_invalidate_lock(bdev->bd_inode->i_mapping); err =3D truncate_bdev_range(bdev, mode, start, end - 1); if (!err) err =3D blkdev_issue_secure_erase(bdev, start >> 9, len >> 9, GFP_KERNEL); filemap_invalidate_unlock(bdev->bd_inode->i_mapping); + inode_unlock(bdev->bd_inode); return err; } =20 @@ -184,6 +188,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev,= fmode_t mode, return -EINVAL; =20 /* Invalidate the page cache, including dirty pages */ + inode_lock(inode); filemap_invalidate_lock(inode->i_mapping); err =3D truncate_bdev_range(bdev, mode, start, end); if (err) @@ -194,6 +199,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev,= fmode_t mode, =20 fail: filemap_invalidate_unlock(inode->i_mapping); + inode_unlock(inode); return err; } =20 --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597 From nobody Sun Feb 8 07:08:29 2026 Received: from fra-out-009.esa.eu-central-1.outbound.mail-perimeter.amazon.com (fra-out-009.esa.eu-central-1.outbound.mail-perimeter.amazon.com [3.64.237.68]) (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 93BB625D540; Tue, 21 Oct 2025 07:13:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=3.64.237.68 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030790; cv=none; b=q8AX6M2lA9qJQFVkpMPaMJu1mCNUzSfCbnGOUdQ0IptHpP5hm19rjDSuQYELpGR0g2lI77+prFplQ7fHNAtEJuk4iWZB8fofTP16ZNlPTolZ35jXBse1V//HEeZ/66DSi9EOi3mTYkL5gcMcv1hhUYldspp6kkwopOT44ohwz9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761030790; c=relaxed/simple; bh=YYP+JvL1Azmf39UNxyLGq9iTQvod6ds7wDUTSE8XiV4=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mANOf2I/adJ3RK0mightC62I+YHhDWpXs99XVYEd6lzctln/mdcQ0MeIFDvO/Pdv0TBdJ2kqyHQwwnL26/wUyu15btV060PEP9FhSjjZj9GBux+jHrsZyfRNzPSd3cEVsYTJq1R2MnFmaoduQFjvcNw/EZTru7nTaDfYew4lV0w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de; spf=pass smtp.mailfrom=amazon.de; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b=ZFYESqTi; arc=none smtp.client-ip=3.64.237.68 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=amazon.de header.i=@amazon.de header.b="ZFYESqTi" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.de; i=@amazon.de; q=dns/txt; s=amazoncorp2; t=1761030788; x=1792566788; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JG6/21Kc3LPmm7ifFU0zEa7/qVfomGnzIkk8iphJ08Q=; b=ZFYESqTis0Cp8Ld/BdgJrwAS7Y6xqQIo5/P0c4kFTT3BPHa3kHCGZPm3 3VqqweZuZTlQpC/Y7lipA6uFG+gY+O4NKr3Q0BSyMrv3//GR2NdIGE7U5 23qj2egJCXzUn9G8zJtR1BV0MJz4a1UVGM0tJFPwwD4RXd8qFJjZLBEKk cCf3rg11OJYRtoK9QTDfSdoVilAY7cnIzjyeUV2gPD0Wr58OwuhlDnip9 8fFtABBR6m1CrXMY7itaGZfEFjI+WZ8VfrH340ODVjnX2b3wfXIx1T6Bs GOMhN3eRhFSBUBaka6JliQY6q9xZFFiwHk8BwEDup6FnkVRc59ARIYapa Q==; X-CSE-ConnectionGUID: 9ajDuW3IRAqJTQOmqwROGg== X-CSE-MsgGUID: w3M+VODYSFGUxfTSLykcsw== X-IronPort-AV: E=Sophos;i="6.19,244,1754956800"; d="scan'208";a="3832773" Received: from ip-10-6-3-216.eu-central-1.compute.internal (HELO smtpout.naws.eu-central-1.prod.farcaster.email.amazon.dev) ([10.6.3.216]) by internal-fra-out-009.esa.eu-central-1.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Oct 2025 07:12:56 +0000 Received: from EX19MTAEUC002.ant.amazon.com [54.240.197.228:1068] by smtpin.naws.eu-central-1.prod.farcaster.email.amazon.dev [10.0.47.14:2525] with esmtp (Farcaster) id 1553515b-eb11-4da4-8ddb-b9d47464950e; Tue, 21 Oct 2025 07:12:56 +0000 (UTC) X-Farcaster-Flow-ID: 1553515b-eb11-4da4-8ddb-b9d47464950e Received: from EX19D013EUB004.ant.amazon.com (10.252.51.92) by EX19MTAEUC002.ant.amazon.com (10.252.51.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:12:55 +0000 Received: from dev-dsk-mngyadam-1c-cb3f7548.eu-west-1.amazon.com (10.253.107.175) by EX19D013EUB004.ant.amazon.com (10.252.51.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.20; Tue, 21 Oct 2025 07:12:46 +0000 From: Mahmoud Adam To: CC: , , Ryusuke Konishi , , , Andrew Morton , Jens Axboe , Xiubo Li , Ilya Dryomov , Jeff Layton , Alexander Viro , Theodore Ts'o , Andreas Dilger , Jaegeuk Kim , Chao Yu , Christoph Hellwig , "Darrick J. Wong" , Trond Myklebust , Anna Schumaker , "Matthew Wilcox (Oracle)" , Hannes Reinecke , Damien Le Moal , Luis Chamberlain , , , , , , , , , , Subject: [PATCH 6.1 8/8] nilfs2: fix deadlock warnings caused by lock dependency in init_nilfs() Date: Tue, 21 Oct 2025 09:03:43 +0200 Message-ID: <20251021070353.96705-10-mngyadam@amazon.de> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251021070353.96705-2-mngyadam@amazon.de> References: <20251021070353.96705-2-mngyadam@amazon.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: EX19D036UWC002.ant.amazon.com (10.13.139.242) To EX19D013EUB004.ant.amazon.com (10.252.51.92) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Ryusuke Konishi commit fb881cd7604536b17a1927fb0533f9a6982ffcc5 upstream. After commit c0e473a0d226 ("block: fix race between set_blocksize and read paths") was merged, set_blocksize() called by sb_set_blocksize() now locks the inode of the backing device file. As a result of this change, syzbot started reporting deadlock warnings due to a circular dependency involving the semaphore "ns_sem" of the nilfs object, the inode lock of the backing device file, and the locks that this inode lock is transitively dependent on. This is caused by a new lock dependency added by the above change, since init_nilfs() calls sb_set_blocksize() in the lock section of "ns_sem". However, these warnings are false positives because init_nilfs() is called in the early stage of the mount operation and the filesystem has not yet started. The reason why "ns_sem" is locked in init_nilfs() was to avoid a race condition in nilfs_fill_super() caused by sharing a nilfs object among multiple filesystem instances (super block structures) in the early implementation. However, nilfs objects and super block structures have long ago become one-to-one, and there is no longer any need to use the semaphore there. So, fix this issue by removing the use of the semaphore "ns_sem" in init_nilfs(). Link: https://lkml.kernel.org/r/20250503053327.12294-1-konishi.ryusuke@gmai= l.com Fixes: c0e473a0d226 ("block: fix race between set_blocksize and read paths") Signed-off-by: Ryusuke Konishi Reported-by: syzbot+00f7f5b884b117ee6773@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D00f7f5b884b117ee6773 Tested-by: syzbot+00f7f5b884b117ee6773@syzkaller.appspotmail.com Reported-by: syzbot+f30591e72bfc24d4715b@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3Df30591e72bfc24d4715b Tested-by: syzbot+f30591e72bfc24d4715b@syzkaller.appspotmail.com> Signed-off-by: Andrew Morton Signed-off-by: Mahmoud Adam --- fs/nilfs2/the_nilfs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/nilfs2/the_nilfs.c b/fs/nilfs2/the_nilfs.c index be41e26b782469..05fdbbc63e1f5f 100644 --- a/fs/nilfs2/the_nilfs.c +++ b/fs/nilfs2/the_nilfs.c @@ -680,8 +680,6 @@ int init_nilfs(struct the_nilfs *nilfs, struct super_bl= ock *sb, char *data) int blocksize; int err; =20 - down_write(&nilfs->ns_sem); - blocksize =3D sb_min_blocksize(sb, NILFS_MIN_BLOCK_SIZE); if (!blocksize) { nilfs_err(sb, "unable to set blocksize"); @@ -757,7 +755,6 @@ int init_nilfs(struct the_nilfs *nilfs, struct super_bl= ock *sb, char *data) set_nilfs_init(nilfs); err =3D 0; out: - up_write(&nilfs->ns_sem); return err; =20 failed_sbh: --=20 2.47.3 Amazon Web Services Development Center Germany GmbH Tamara-Danz-Str. 13 10243 Berlin Geschaeftsfuehrung: Christian Schlaeger Eingetragen am Amtsgericht Charlottenburg unter HRB 257764 B Sitz: Berlin Ust-ID: DE 365 538 597