From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=160.101.131.9 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380727; b=Vobu3hAn5TajhKwtdZluXXG/RFPa1KZ7mrTfjDa/1tn1rZd0F8H8rb+PuOXYWwfStweU pHgcK+vzmRZEl2U02E8+maKpa0scXuqys3P5JoqM4xsQi2zR5lRw9Hj+CNqffcQS2Qwnq aiwOjUPIC9fhnifDjpnxj/tSPhv7T9NAzQpjNcS0sc75dvm8h2zfxB14WyOMGVCmmNPDS gBUjlyqPzcwgvGM/g5fMSqm620AAMCgGRCbcQBLCt3cdmWofFu17ZYT9SqTzgVkykxnNG U4uZElyhsX8A2FICAY8b22Ogz35XkpaK7OQkUzjTl3c0hHd5CGBhchfnAhp4yZ/5XBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380727; h=DMARC-Filter:Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer: MIME-Version:Content-Transfer-Encoding; bh=QyHoO49ljTlz6HALn7hEHlqG7+pljFTJ/G4RqMbx6H0=; b=Bp5Dt9TTzxSE3zESXH9ObLuiEelU78rQb3qN4wU+eEgVaJcMxXzKECKzKGGU77ClpQTB QLuSmWMvN86vq3JOxtAlV8rrnusGRNSAClOLWxH/VQDTnU0pbz17Vsv0zqG/f/NRY5p2D 5hkmRwIDvW8/63WPsVCiJwIw1GP3KGTtd2tOZbnMHQh9PLl0BECz0aG7wGMgM85uaxJ7G pCdsASANG8nvVoutHwwk4ar9Tdk81EATGpJJ7TXSgZzmPPrYfPgRPyeEUE+8gSHuG7+DY Pqdl1Q2Ik7HOed3im7ukkVvRIfxBSuKLQOcTlOI6WlAry763EDXBkjmqCgGuNP8nzDQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=citrix.com; spf=pass smtp.mailfrom=citrix.com; arc=none smtp.remote-ip=160.101.131.9 Received: from na1pdmzitismtp02.tibco.com (na1pdmzitismtp02.tibco.com [160.101.131.9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DB0EE606A322; Fri, 4 Dec 2026 10:38:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org DB0EE606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=citrix.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=citrix.com Received: from mewpvdipd1070.citrite.net (unknown [10.113.40.46]) by na1pdmzitismtp02.tibco.com (Postfix) with ESMTP id B28C185E47F1; Fri, 4 Dec 2026 05:36:47 -0500 (EST) From: Mark Syms To: stable@vger.kernel.org Cc: Mark Syms , linux-cifs@vger.kernel.org, Steve French , Paulo Alcantara , David Howells , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH 6.6.y] smb: client: don't truncate the file when punching a hole Date: Fri, 4 Dec 2026 10:38:38 +0000 Message-ID: <20261204103838.830548-1-mark.syms@citrix.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit smb3_punch_hole() moves the server's EOF out to cover dirty data whose size update the local hole punch dropped, and decides whether to from the netfs remote_i_size. This tree's cifs does not maintain remote_i_size: it is set at inode init and on copy/clone only, so for any file that has grown since, the "extension" truncates the file to the end of the hole: truncate -s 64M f; fallocate -p -o 1M -l 512k f -> 1572864 bytes qemu passes guest discards through as punch holes, so a guest's first discard cuts its image short and every block allocated above the hole is lost. Ask the server for its EOF instead, so the call can only grow the file. Fixes: 288d398df80c ("cifs: Fix FALLOC_FL_PUNCH_HOLE support") Assisted-by: Claude:claude-opus-5-5 checkpatch Signed-off-by: Mark Syms --- This is a fix for 6.6.y only. Mainline is not affected: since the netfs write conversion, remote_i_size is maintained on every write, so the check in smb3_punch_hole() is correct there. 6.6 got the check from the backport of 416871f4fb84 (6.6.49) without that maintenance, and every 6.6.y release since (checked through 6.6.163) truncates a file that has grown since its inode was loaded when a hole is punched below its EOF. It depends on query_server_eof() from 74f39fa28286 ("smb: client: only require read lease for size extending ops"), which is in 6.6.163. Found as qcow2 images on an SMB share being cut short by guest discards passed through by qemu. Tested on 6.6.138 with the 6.6.158-163 smb client fixes applied: the reproducer above keeps 67108864 bytes, and a qemu-io discard/zero-range pattern test verifies clean. fs/smb/client/smb2ops.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index 84acf669f88a..20b4072314bd 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3414,15 +3414,25 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, * of the high end of the hole and the proposed EOF. The problem is * that we locally hole-punch the tail of the dirty data, the proposed * EOF update will end up in the wrong place. + * + * Ask the server where its EOF is: this tree does not maintain the + * netfs remote_i_size, and a stale one turns this into a truncation + * of everything beyond the hole. */ + rc = query_server_eof(xid, tcon, cfile, &remote_i_size); + if (rc) + goto unlock; i_size = i_size_read(inode); - remote_i_size = netfs_inode(inode)->remote_i_size; if (end > remote_i_size && i_size > remote_i_size) { unsigned long long extend_to = umin(end, i_size); rc = SMB2_set_eof(xid, tcon, cfile->fid.persistent_fid, cfile->fid.volatile_fid, cfile->pid, extend_to); - if (rc >= 0) + if (rc >= 0) { netfs_inode(inode)->remote_i_size = extend_to; + spin_lock(&inode->i_lock); + CIFS_I(inode)->server_eof = extend_to; + spin_unlock(&inode->i_lock); + } } unlock: -- 2.56.0