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 8D7C63C063A; Wed, 30 Sep 2026 18:58:08 +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=1790794689; cv=none; b=bfVBGw2RJM6mqlGk4vAU+CVyilVebjEInwFLJC1NSVp/44InLnEI8+4vYXY0VI5Ms22hNFOXvq3yclUH3ZTQ+Kt6nlEnm5CJG6ovRE4prFCEXGFRzsCEdPKKZZXsWpiytp+K+mrpBrw2vBRMy2fl9rvLdl64SCKCoJ+mQu9AssE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790794689; c=relaxed/simple; bh=MiCtGJ4obX3iIsiXLS0Uahg22C9QLgSU8aUJBHXqb4s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ldmSShCDqyL0iSNolMJWaC73+qGJ13LdGjnqefDjTu/3eTjL8tN50c1MiZrDUf4RTLc009BV+UCoEQ7oX3xIrR5oUbkt2w765Pd20HXRqYhDhGsvLFVfuzxf077O//wkl4sfog+qeaOnXolJr+d/RENkFdGV2OIJgZcSFzrAjDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=cGPVP5/y; 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="cGPVP5/y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EACB11F000FF; Wed, 30 Sep 2026 18:58:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1790794688; bh=uoClNBGNGozD1OGFhNg3Ga1NrULuJKZPbUNWbwthWKY=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=cGPVP5/yaDUbEhUPdXP8erd6s6KKk19Ew8Ic69lNpSu2FOD2W5Cr1oP/i19Ayblks qS2jHmuqoGILvrcjxiJya6DU62hHz1ZINFt+KKSkLPxofGf2ICSpH0N3vCGAvgOh9t +6LsfsMwG2C4dudySla5BQMZwvnfz3WwA931t/jQ= 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.6 0299/1193] smb/client: reduce fallocate zero buffer allocation Date: Wed, 30 Sep 2026 17:16:23 +0200 Message-ID: <20260930152440.799064491@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260930152434.301151190@linuxfoundation.org> References: <20260930152434.301151190@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.6-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 8a15694c1bbb5..07ed4bfd40977 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3379,7 +3379,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]; @@ -3400,9 +3400,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; } @@ -3432,7 +3433,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