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=1796381600; b=VSxeZJYsTLVQVJADy2MgOuXF9JCryJzq0DoAzxfR0s6Nu/bLNuoFe2TFYmzzWcq1DV7Q gsO6X0UrLs9SPRGJQ1E0XY3fwjRQ38NQDd3vPx2SkGeFiVJcW1zBrQ/1cf6T8uSkSyD/E C1oQzNl1Jh0HwaNIT8ElGcbpezX9I4Ef3XPPdqWOcvXJguBgUkJ2rh+mEvZHNbDgMb2A5 NkzJ4Dx+chyjJpzd1vGEnl3+9C7eABgEbSpqi665kP64tehBLqD5scDkgmZRleuhumUL4 cdzBXsmMr0d2GCkR2Zlp810Wf+AYnURo5GeeEWg2m6HCGCTBqIM0XlIx6KPvIr9hvNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381600; 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=cEg9wEsyIlbCOhMxD1tfbbkHcgNmGNMffskst6wlv3I=; b=zIKbKxwGXgj3hWpjNO31fyPVn/61CKMjaYWbnhZE/9KJpdNGr+XdFr88KR7rmFSj9wpd LlXphdqfmtbGBPMccUMzN8Xeb2ew9BVXTMwTcPQhvoWi6QabK8KTXkz0xPtRMv6ExfP9+ fcmnXdkPAsh/gzlmjWVzTFd8R/Pq+OJZPD32Nsfmbk+xecTKjJPY35TlqWuqw7d7V2vqX JUFsRsRxWDn2gfMrPAM5OzqvMj6VQWT3dy/pALM+52F7sm91rM0TM0URBDmj+G05Qfoyp yIqXJbeATGOYhs4o/jb+QKs0JInCSSctJa0oadUoI6IZGhghApCOjSmtBXrZaQ4XcIw== 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=pSf2D8Ep; 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 C354A606A32C; Fri, 4 Dec 2026 10:53:20 +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=pSf2D8Ep Received: by smtp.kernel.org (Postfix) with ESMTPSA id 00CB41F000CE; Fri, 4 Dec 2026 10:53:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381600; bh=cEg9wEsyIlbCOhMxD1tfbbkHcgNmGNMffskst6wlv3I=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=pSf2D8EpHJA8S0rwi6kd3vqUTmRsPObWvNi5C6j5h+8Fdyf2qCSZuIIvDNMTvtTn0 MrTrq9TZI1ZMQmMEQDfv4B02of/qT511v2BTq/UO/TfW2AA/zV3G6PAZjmqgk6+Q5R 4GolmSH6H0Z3TiVFPVChodGwX39P3Z+lPBccjiuQ= 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.18 092/703] smb: client: dont write back through O_DIRECT handles Date: Fri, 4 Dec 2026 18:59:51 +0900 Message-ID: <20261204100630.190555218@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@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.18-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 FIND_* flags to this tree's FIND_WR_* names, used bit 3 for the new flag, and dropped the tmpfile hunk because that code is absent. ] 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 ea6533d057acf..2660a3a0f51cb 100644 --- a/fs/smb/client/cifsglob.h +++ b/fs/smb/client/cifsglob.h @@ -1868,6 +1868,7 @@ enum cifs_writable_file_flags { FIND_WR_FSUID_ONLY = (1U << 0), FIND_WR_WITH_DELETE = (1U << 1), FIND_WR_NO_PENDING_DELETE = (1U << 2), + FIND_WR_NO_DIRECT = (1U << 3), }; #define MID_FREE 0 diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c index 652206fead33c..e11662f2a903c 100644 --- a/fs/smb/client/file.c +++ b/fs/smb/client/file.c @@ -282,9 +282,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; } @@ -2669,6 +2675,9 @@ cifs_get_writable_file(struct cifsInodeInfo *cifs_inode, int flags, if ((flags & FIND_WR_NO_PENDING_DELETE) && open_file->status_file_deleted) 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