From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 D2DFA4E0B93; Thu, 17 Sep 2026 18:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789668376; cv=none; b=g5u7WAis7gA/aZq56FekuFoEeixHARC6/kyXp+E2l2LcQHF3IW8xXqvOgZqexsbhYFL5OpV9w5kG43QCe5c9XBfgeb0m/OioqHkNsY5S5qOvDzxfpanHJ6g594v5ehmNH+AysCztuT1yBXwNhtwG6Pmyvrfkj4AKsD2X4h92pB4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789668376; c=relaxed/simple; bh=IQ2itAORLKsmu99ZNZaLg/ohPpu2XeVcVrHcbTbRh2Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MhQD/4P/W2DsRbYlaEcAD7fEfniRDIXIiHwLYnGzHFvlqBL9FLiMHXfnlYbxxxxyp6COXuSs9i8+9UyuqNHJ4IA2juD4QnGE7t9q0YhPPpr41ymiA10iplN4G7RfE03fEkZtEMuPcwr+XN2WvScPL7BJVptGptPXVN2ax5jHqE8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=QR/rHQXu; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="QR/rHQXu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2EF401F000FF; Thu, 17 Sep 2026 18:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789668374; bh=V00hhl68NtJlsnBgkfdhTlvCvdQSHLH3gaIOuo3sEOs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=QR/rHQXujX0g8YPonSgpBvXBftTgEmnf45jwDHabotgf57OjIQvvpmZ+fggENnsAm aj/Op96A2RBiRgsDGxEZytWRLbkKlMMQgjKD1jJn6C1GlUxjQwyo/w+g7Fy8fys/j+ XGdh5yqoP3ORBjGUHcxg8GIcPXoxYpcw6m/7n/NU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Huiwen He , ChenXiaoSong , Steve French , Sasha Levin Subject: [PATCH 6.12 0403/1102] smb/client: reduce fallocate zero buffer allocation Date: Thu, 17 Sep 2026 16:05:46 +0100 Message-ID: <20260917151549.778500916@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151539.408551884@linuxfoundation.org> References: <20260917151539.408551884@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Huiwen He [ Upstream commit 9e4ec3be67af41ab859302d7109b34976efd9258 ] The fallocate emulation allocates a 1 MiB zero-filled buffer even though each SMB2_write request is limited to SMB2_MAX_BUFFER_SIZE, which is 64 KiB. A high-order 1 MiB allocation is more likely to fail on a fragmented system. Allocate only the smaller of the requested range and SMB2_MAX_BUFFER_SIZE, and reuse that zero-filled buffer for every write request. Also reject a successful write that makes no progress to avoid looping indefinitely. This reduces the contiguous allocation required by fallocate emulation without changing the written data or range semantics. Signed-off-by: Huiwen He Reviewed-by: ChenXiaoSong Signed-off-by: Steve French Signed-off-by: Sasha Levin --- fs/smb/client/smb2ops.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index e99b8e1f66d4f..3119d664e8684 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3442,7 +3442,7 @@ static int smb3_simple_fallocate_write_range(unsigned int xid, char *buf) { struct cifs_io_parms io_parms = {0}; - int nbytes; + unsigned int nbytes; int rc = 0; struct kvec iov[2]; @@ -3463,9 +3463,10 @@ static int smb3_simple_fallocate_write_range(unsigned int xid, rc = SMB2_write(xid, &io_parms, &nbytes, iov, 1); if (rc) break; + if (!nbytes) + return -EIO; if (nbytes > len) return -EINVAL; - buf += nbytes; off += nbytes; len -= nbytes; } @@ -3495,7 +3496,7 @@ static int smb3_simple_fallocate_range(unsigned int xid, if (rc) goto out; - buf = kvzalloc(1024 * 1024, GFP_KERNEL); + buf = kvzalloc(min_t(loff_t, len, SMB2_MAX_BUFFER_SIZE), GFP_KERNEL); if (buf == NULL) { rc = -ENOMEM; goto out; -- 2.53.0