Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 8A320286409 for ; Tue, 14 Jul 2026 07:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784013298; cv=none; b=Xn5DLMAs5Z4iJDECw8J+/ofin3PHasp+bMUvhUY7Eesiy+JtmmRrKkQqon+qWMlow+uBYpjZeGFHZxKOcvnDokZ7Tchye6a8GT4P1cZ6D6js33PNg62jrq7KBfafgD180lGMq4iKAOE4awC+hXS7prC4G4M6LNceexDtSlRwMIc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784013298; c=relaxed/simple; bh=IszOu8Yca3+bolpqXkQ2DYYwxVIKmj73RwQpc37dJ3Y=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=gSF1hNRNUHL6O0Tkt2Van70Ak77B999T+iN5EaTs2usAtp9qTbxPPWvHEsaVgCo/lgzXK2tNq55T9NNXtmk+1u83B3A2p01q+J8NmctoKlp97UuUqvz75DFEH9+JQk1f4n/n9KHlj63sX52tRD7gDAdYSypjHbjMCkdKSXZQBZE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=pCBqbYoP; arc=none smtp.client-ip=91.218.175.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="pCBqbYoP" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784013294; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=gvRqTgUMzgV1aouKJNuI/J1zwo539DziNE3P13worEM=; b=pCBqbYoPW7X18YjK/QdA2eOotJUZO/oxjANjUQ5VcX/BtbkZuFm6g/bCymaJOgbpLLeybP K9Ff+0mfoLz4HqkK31KIVh1eNXizXnuZvoWxmP2hGkCBCMSwpY2hA1gx7vuO2pMdeMqF7Q yJqa+bo47w3rGqDI1dsy3hC77Ozv2Us= From: Huiwen He To: smfrench@gmail.com, linkinjeon@kernel.org, pc@manguebit.org, ronniesahlberg@gmail.com, sprasad@microsoft.com, tom@talpey.com, bharathsm@microsoft.com, senozhatsky@chromium.org, dhowells@redhat.com, chenxiaosong@kylinos.cn Cc: linux-cifs@vger.kernel.org Subject: [PATCH] smb/client: flush dirty data before punching a hole Date: Tue, 14 Jul 2026 15:13:39 +0800 Message-ID: <20260714071339.137702-1-huiwen.he@linux.dev> Precedence: bulk X-Mailing-List: linux-cifs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT From: Huiwen He Punching a hole after a large buffered write may leave the range reported as data. Reproduce it with: xfs_io -f \ -c "pwrite -b 3m -S 0x61 0 3m" \ -c "fpunch 1m 1m" \ -c "seek -h 0" \ -c "seek -d 1m" \ /mnt/test/repro Punching 1 MiB at offset 1 MiB should produce: 0 1 MiB 2 MiB 3 MiB | DATA | HOLE | DATA | EOF Instead, the entire file is reported as data. SEEK_HOLE(0) returns EOF, and SEEK_DATA(1M) returns 1M. This happens because a dirty folio spanning the punched range can be written back after the punch and refill the hole. Fix this by flushing and waiting for dirty data in the punched range before invalidating the page cache and issuing FSCTL_SET_ZERO_DATA. The xfstests generic/539 pass against Samba/ksmbd with this change. Signed-off-by: Huiwen He Reviewed-by: ChenXiaoSong --- fs/smb/client/smb2ops.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c index ce34b3fbfca3..ac62e53b42e1 100644 --- a/fs/smb/client/smb2ops.c +++ b/fs/smb/client/smb2ops.c @@ -3489,6 +3489,15 @@ static long smb3_punch_hole(struct file *file, struct cifs_tcon *tcon, } filemap_invalidate_lock(inode->i_mapping); + /* + * Flush dirty data first, otherwise a dirty folio spanning the punched + * range may be written back after the ioctl and refill the hole. + */ + rc = filemap_write_and_wait_range(inode->i_mapping, offset, + offset + len - 1); + if (rc < 0) + goto unlock; + /* * We implement the punch hole through ioctl, so we need remove the page * caches first, otherwise the data may be inconsistent with the server. -- 2.43.0