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=1796383188; b=COBfgw75S7hB7grGSDtH6Tmjbj9NysDO2OKFNtdyfMIfg6hmPm+qxOdGaiy0XVn/D3l2 o07G27e0xQzrG6dSib9uJCyrVSoq4Ovs6mmM/cUjCaFe0w8AG6kOTGSOkNtN1uB1jECJw GPll++RSb3PVT8d7dvhHcVPSa/WY5IDPjIOowcHRTw4cfZTWcpksO+VJrixSHdaGfdA++ lyvcsmuZ2yL+Yp3bC5wslwBVxg4InNSa5jHgPktCoRfpzJCekhvoO9HF7qD804ETywyZK hgU/BxBffzf3XvhVhdyuI0hzXtn4p+1G4ZpgH8y+cXeV6AoFD51Y7uItuPvlWFSh50A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796383188; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=jtEnj05QdMa/WJm6UhqPHrb/ESRreLiyk0k1oXgJf1w=; b=neprx8AM0f978YZPUQtCxOKyS6yuGBZHiIssn6MN4FE3IA2bIvO9OAzwlF91wB8moY04 xrGCuoEdH/hmYuVMf/6TPY/hKsId0qZVrsDamjmtguPgn77kOUV517C2OWkMe23vQa28o LGzIaBI79i5kzHQEQI2puOM3RwFEpaPQEQJuLytX+AfkvFnjTTkiSBOUzQL3tDFUP4Cp/ pQIUlbxCW+DDFHfGKtBPQoaEW1KKcAzh5UeJMfPgMhYx4dCjnsI3FdtwXiSv2HqdvAQTV i6xPtYcKmRJKQQ6btTBpzWj8qyFP3aWrEwiUZ1p9LgOQBxZ0co7By2HMjEyRwAsGyXw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=dXUM4EuR; 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 07986606A32D; Fri, 4 Dec 2026 11:19:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=dXUM4EuR Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F701F00933; Fri, 4 Dec 2026 11:19:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796383187; bh=jtEnj05QdMa/WJm6UhqPHrb/ESRreLiyk0k1oXgJf1w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=dXUM4EuRzGfZRy27b4xArT7gfzxrT8xuPeDr8YNhz5VYpq9vB4kJ+kCYyG3HsLdYz rjAAp1bsn4EHJ564PjUKlPeKG2zJQBA+dzb11Rx7XOyMOuKGaHd7KR0Nj+pxmR+eFg B6ZuxcCRR+T9KjmEIP5/BO2YEaB0ryx0D8M/gRfY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, David Howells , Paulo Alcantara , Sasha Levin Subject: [PATCH 6.12 118/555] smb: client: dont write back through O_DIRECT handles Date: Fri, 4 Dec 2026 19:02:41 +0900 Message-ID: <20261204100612.396184552@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Paulo Alcantara [ Upstream commit 0e85145af984f7cae2aadaa694cb8612009027ac ] Writeback uses the first writable handle of the inode, which may have been opened with O_DIRECT. Such handles are opened with FILE_NO_INTERMEDIATE_BUFFERING, for which Windows rejects any unaligned I/O with STATUS_INVALID_PARAMETER. Writeback of partly dirty pages and of the unaligned tail of a file through one of them fails, so netfs ends it with the folios clean and the data never reaches the server. xfstests generic/051, where fsstress mixes both kinds of opens, loses about 1% of its writes this way: smb3_write_err: ... offset=0xde90d7 len=0xbd0b rc=-22 All the rejected writes in a network capture were unaligned writes on a no-buffering handle; none of the aligned ones, and none of the unaligned ones on regular handles, were. Prefer a handle that was not opened with O_DIRECT, and use one that was only if there is no other. Fixes: 1013e760d10e ("SMB3: Don't ignore O_SYNC/O_DSYNC and O_DIRECT flags") Reviewed-by: David Howells Signed-off-by: Paulo Alcantara Cc: stable@vger.kernel.org [ sashal: Renamed the FIND_ANY flag to FIND_WR_ANY and added FIND_WR_NO_DIRECT as a #define instead of an enum entry, and dropped the tmpfile hunk since this tree has no tmpfile handling. ] Signed-off-by: Sasha Levin --- fs/smb/client/cifsglob.h | 1 + fs/smb/client/file.c | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/cifsglob.h b/fs/smb/client/cifsglob.h index 27bdb50751852..3fe2144b00d2e 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1815,6 +1815,7 @@ static inline bool is_replayable_error(int error) #define FIND_WR_ANY 0 #define FIND_WR_FSUID_ONLY 1 #define FIND_WR_WITH_DELETE 2 +#define FIND_WR_NO_DIRECT 4 #define MID_FREE 0 #define MID_REQUEST_ALLOCATED 1 diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 4a62787891292..5aaa77ef527ab 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -267,9 +267,15 @@ static void cifs_begin_writeback(struct netfs_io_request *wreq) struct cifs_io_request *req = container_of(wreq, struct cifs_io_request, rreq); int ret; - ret = cifs_get_writable_file(CIFS_I(wreq->inode), FIND_WR_ANY, &req->cfile); + ret = cifs_get_writable_file(CIFS_I(wreq->inode), FIND_WR_NO_DIRECT, + &req->cfile); if (ret) { - cifs_dbg(VFS, "No writable handle in writepages ret=%d\n", ret); + ret = cifs_get_writable_file(CIFS_I(wreq->inode), FIND_WR_ANY, + &req->cfile); + } + if (ret) { + cifs_dbg(VFS, "%s: couldn't find writable handle: %d\n", + __func__, ret); return; } @@ -2554,6 +2560,9 @@ cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, int flags, continue; if (with_delete && !(open_file->fid.access & DELETE)) continue; + if ((flags & FIND_WR_NO_DIRECT) && + (open_file->f_flags & O_DIRECT)) + continue; if (OPEN_FMODE(open_file->f_flags) & FMODE_WRITE) { if (!open_file->invalidHandle) { /* found a good writable file */ -- 2.53.0