From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796145651; b=ONGg4LEurQ84KOh29fiQvaocKa4uPi9tNE+zBuMyEqWMuSdSdYinjphAOikflSf07Br9 x8Oq25p6MlXr5I1RFUSYqir7Xw2G3WeiBNwNvjU7I/WPolNqLQoautrMvDfcIB0KeHJgK YFkcu06rdx9NvR4OWopPHYfz1bX76+pI2fbOUVWM6/K0A/ddlhMbmwAKsyYIC1MY4pDmf AjhjvdQnbFE9xMjTOurHODo28z/63akVd0DwFD0L88TOPpYYrhKXOjB3rBSSA5vaqdoBf 6F+bNv7YiIBx6It+JwW4dTw5c28MVV4EcCNE8XfcWUlbUof6h7YtJ1usBQ5+3ZTeC8w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796145651; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=lQ7OJHXq6Ozhl2ZlNMYLghSglO4p52K7Vg1b/DrqI/U=; b=GixDWCCL7uN2dWoi72ge18w6u8QqaCfNcac/fYHQoUJQDEoY/NdRHt4krZ8fqscci0CD IKBIw//f/OQDmSq8ulp37Xihmrh3O/VPihlsNeFjSrRqpWRxXCbYLbDt0bOpmyeywgtJF Pqv6oFsp1Y/HqdLve3t2R1GF1g1BXwW+sAtGWP8sAVcTGUyIELVrN8NXenfVm9mDFw5RB AAj8uUT4vySndrZfjUdJMdwjg0syY+MvPlXLrFEfT5gJj8TrBGtzE/9ISdAFAHpGfYfQI TWfEKzDe+BcyEYhwBD0r9Y/WBcvnY++lYpbT+qCsGbvrJT2mBeUSwAhGJaXftvsw9uQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NHkDVntf; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 035AE606A31A; Tue, 1 Dec 2026 17:20:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=NHkDVntf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3EA0C1F0089A; Tue, 1 Dec 2026 17:20:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796145650; bh=lQ7OJHXq6Ozhl2ZlNMYLghSglO4p52K7Vg1b/DrqI/U=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=NHkDVntfk0cT7Jm6i1TIGP0EI8Bni1BjxOp6/DWe+x85X94rZD6b+bL/jcc7ifNc1 OwLtSGNyiAvfjH3SJ2Y7GnaYzXlhVfhbe4Nlmg+ZvPAlln0AyTi6kHwsVfJOB4DyVJ +UdA8sMzpGSkNchfEpoucNrpaCE1LgR4jwErt7viSXyfLF4S7e3WLSqYA7BhFQmtAa 5Zad558/iyN1FkKCH9yWIlOxqiaHlH+5/bIEyd/DTRvpB4ISpmqtNoN9sF1WMAQvUO s9EHT2CXaBEUiO0bL/31oDRceFWn5R8WPKpvP4dfldzW0lqvln8l8Uwv3rnR3V31Yf 0Ej3P5nPUcehg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [RFC PATCH v3 12/13] xfs: support dma-buf registered buffers for direct I/O Reply-To: sashiko-reviews@lists.linux.dev To: "Nitesh Shetty" Cc: dri-devel@lists.freedesktop.org, nvdimm@lists.linux.dev, linux-ext4@vger.kernel.org, tytso@mit.edu, media-ci@linuxtv.org In-Reply-To: <20261201155938.3028275-13-nj.shetty@samsung.com> References: <20261201155938.3028275-1-nj.shetty@samsung.com> <20261201155938.3028275-13-nj.shetty@samsung.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 17:20:49 +0000 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] xfs: TOCTOU race and missing dma-buf checks on RT flag and stable writes -- commit 08914e910a1ba46188577502e908fd31c6bc3a3f Author: Nitesh Shetty xfs: support dma-buf registered buffers for direct I/O This commit adds dma-buf direct I/O support to XFS via init_dma_buf_io_ctx and dma_buf_io_tag callbacks, while rejecting dma-buf iterators in the buffered and DAX paths. > diff --git a/fs/xfs/xfs_file.c b/fs/xfs/xfs_file.c > index ad1ce4f99ad88..a8440663d5e95 100644 > --- a/fs/xfs/xfs_file.c > +++ b/fs/xfs/xfs_file.c [ ... ] > @@ -2187,10 +2199,38 @@ xfs_file_mmap_prepare( > return 0; > } > =20 > +/* > + * Direct I/O to devices that need stable pages bounces through the CPU, > + * so they can't do dma-buf I/O. Zoned inodes are not supported yet. > + */ > +static u64 > +xfs_file_dma_buf_io_tag( > + struct file *file) > +{ > + struct xfs_inode *ip =3D XFS_I(file_inode(file)); > + > + if (IS_DAX(VFS_I(ip)) || xfs_is_zoned_inode(ip) || > + mapping_stable_writes(file->f_mapping)) > + return 0; > + return bdev_dma_buf_io_tag(xfs_inode_buftarg(ip)->bt_bdev); > +} > + > +static int > +xfs_file_init_dma_buf_io_ctx( > + struct file *file, > + struct dma_buf_io_ctx *ctx) > +{ > + struct xfs_inode *ip =3D XFS_I(file_inode(file)); > + > + return bdev_init_dma_buf_io_ctx(xfs_inode_buftarg(ip)->bt_bdev, ctx); > +} [Severity: High] Can a concurrent FS_IOC_FSSETXATTR ioctl change the inode's target block device, zoned status, or stable-writes state after the unlocked xfs_file_dma_buf_io_tag() check? xfs_ioctl_setattr_xflags() can toggle XFS_DIFLAG_REALTIME on an open regular file without allocated data extents, which switches xfs_inode_buftarg(ip) between m_ddev_targp and m_rtdev_targp, changes xfs_is_zoned_inode(ip) on zoned mounts, and updates AS_STABLE_WRITES via xfs_update_stable_writes(): CPU0 CPU1 io_init_rw_fixed() io_import_dmabuf_map() dma_buf_io_file_compatible() xfs_file_dma_buf_io_tag() /* tag matches m_ddev_targp */ xfs_fileattr_set() xfs_ilock(ip, XFS_IOLOCK_EXCL) xfs_ioctl_setattr_xflags() /* flips XFS_DIFLAG_REALTIME * and AS_STABLE_WRITES */ xfs_iunlock(ip, XFS_IOLOCK_EXCL) xfs_file_write_iter() / xfs_file_read_iter() xfs_ilock_iocb() /* proceeds with ITER_DMABUF_MAP on new device/state */ The direct I/O paths never re-validate the dma-buf tag or reject ITER_DMABUF_MAP after acquiring XFS_IOLOCK: - On a non-zoned mount with an external realtime device, xfs_bmbt_to_iomap() binds iomap->bdev to the newly selected device and iomap_dio_rw() submits REQ_DMABUF bioscarrying a dma_buf_io_map mapped for the old device to the new one (causing bio->bi_io_vec / bio->bi_dmabuf_map union type confusion if the new driver does not support REQ_DMABUF, or invalid DMA addresses across devices). - On a zoned mount, if XFS_DIFLAG_REALTIME is set before xfs_file_dio_write= () checks xfs_is_zoned_inode(ip), it dispatches to xfs_file_dio_write_zoned(), which (unlike xfs_file_buffered_write_zoned()) does not reject iov_iter_is_dmabuf_map(from). - In xfs_file_dio_read(), if mapping_stable_writes() becomes true, it calls iomap_dio_rw() with xfs_dio_read_bounce_ops and dio_flags =3D 0 (without IOMAP_DIO_BOUNCE or an iov_iter_is_dmabuf_map(to) check), so iomap_bounce_read() and iomap_ioend_unbounce() dereference orig_bio->bi_io_vec (aliased with orig_bio->bi_dmabuf_map) as a bio_vec array. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201155938.3028= 275-1-nj.shetty@samsung.com?part=3D12