From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.168.172.155 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796364378; b=ASJAUjs8OUj4Ly6+m9WEh4kcqbi6yG+V93i7aFb84hdlywCg7qO0As+tkKXtjgnY1LKv StC+PI+f4h3EkfE8TdMwlj4GoxSGkDVzX00xXqiD08DhvrR9oRmb1tDVOnRaSzG6tDpNS 62FQrxYUj3PuSpMxNUS2O3GW6nNs45FMWDC1STOEDb4rgTR8PZ8JcJ+2dx38dRkdhQX7Q bmoRAG27NxyIEM7ew38nJCdkX5FRm7vj3I5RPMrNyk92zoouFunvfwo+ZKy/4SnaTCc0b trR/z8iSHaxSFfXQxMPdleQCJdA12QcGtyew9ed/FdmHWdzfL/YZydYk+P1ar8GjPTA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796364378; h=DMARC-Filter:Received:Received:DKIM-Signature:DKIM-Signature: X-DKIM2-Info:DKIM2-Signature:X-DKIM2-Info:Message-Instance: X-ME-Sender:X-ME-Received:X-ME-Proxy-Cause:X-ME-Proxy:Feedback-ID: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; bh=saYL88Oz+8Naw/UupDoWjqmdnBipQosfu6qOvPGJlXQ=; b=nawb/OP2Mj4qWSaQMdGGtzezGr/QUJzZFDmVW+87U6gou3UKYgnL83G5q0XI1lPd3dxV pemn65+41dgJTsQ3xcpDsxDbmAMTnWlNlKRvLh3Pa+zvTTKXA98HkWmOFoETzFuGCS7Qq P2Sty+RIVyDQK5YzqSvxyACdKOS0ZgmU1IN5OIDf+l5+Cu/L1yG9iV0D2mTMNIV2fMhHa pHWjkDnoUa0wkyvNN0SFeMBKqQ8/KXWwuGfB9nNAf6Kt0YTAsC7JsSonBWUCuNLr2lWpQ d6xKg69M+M2PzM8FM5kNQ3ELfWYnoD55pz19suR73UuvXmR78v9j24Lc3KJTu5wvQ9A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=fastmail.org; spf=pass smtp.mailfrom=fastmail.org; dkim=pass header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=tQXeLs6h; dkim=pass header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=UFdCm6a1; arc=none smtp.remote-ip=103.168.172.155 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 3289E606A32D for ; Fri, 4 Dec 2026 06:06:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 3289E606A32D Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=fastmail.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fastmail.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=fastmail.org header.i=@fastmail.org header.a=rsa-sha256 header.s=fm3 header.b=tQXeLs6h; dkim=pass (2048-bit key, unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.a=rsa-sha256 header.s=fm3 header.b=UFdCm6a1 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4C9F6140017D for ; Fri, 4 Dec 2026 01:05:07 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-06.internal (MEProxy); Fri, 04 Dec 2026 01:05:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.org; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm3; t=1796364307; x= 1796450707; bh=saYL88Oz+8Naw/UupDoWjqmdnBipQosfu6qOvPGJlXQ=; b=t QXeLs6h33RGlQavmok+/gP3DYNQxaGioisQl0NMeDpqfdBmifWTO29YPaQokEhso rEei876qOyw+S5Z4NLNjC0o0XJW2Ew4d3EymdboKZ4erEIcITHNWa+WYXnpUo284 c8JCxQ+9cMsH+Nc6ATOhJsxftWGoYdeaV3s7KoUMls16IKWiRr2Jw3fyu3g5MhNb iT2y+TKAsAohg0LugeG6l6kWmMYzjoUqFADhmMMRKzmLp3+1Gmn9q3hRUM/sSDGi rZ7PjseNeyo+qfLyF38CuNOUPqXvFfGgOn7RiOnS+GHvRCZ4UAd90ibjpA8fBnxI Z7oM3V8n6aRbC7fwVXV8w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1796364307; x=1796450707; bh=s aYL88Oz+8Naw/UupDoWjqmdnBipQosfu6qOvPGJlXQ=; b=UFdCm6a1ZgFJidFBy u0+kCMID/h69S3ohFWC87lghHez1I4MMo7XNNT41f4Txotl+tv06VdQKbUO1Fj0s VlswFKVZJiOTaY8iEC6vIkEyUVJtAgibPKOGrKByEf4+E6FxWV3h1eN/8IlTXB3x nUyCvYQaEazs6BeJrVEVwBCgVI/w+H8EBR/DMIbcaaCMwrVqpJwKbbDQovSlx5eU 9L15ICyPdgbyrVL6py275f8v/aP6au33HHn9C6GLmg7I0YVoz53ooQ5mI1DA+RfT nmQCNcCuGiEtsl5PUk3jn9UaozjFl8uOfF5UuQ5dua3AexYrRhmR0UbrudwodRK/ VqoQQ== X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=sign d=fastmail.org a=rsa-sha256; DKIM2-Signature: i=1; m=1; t=1796364307; d=fastmail.org; mf=PGljYkBmYXN0bWFpbC5vcmc+; rt=PHN0YWJsZUB2Z2VyLmtlcm5lbC5vcmc+; s=fm3:rsa-sha256:u4R60sCEyLm4g38dVqI6acN2O8T1pWYwgRAVWJTN+zobKqI gwIJdDunwLJWORS+iD0gshpBD/iN0HPtaSDCgsUBlY5bZePT8UhXovjZpYAIEVNr VqgYjRewvI+mDizEzFEVvnN0RqWFUvNE7IOXJKHEqf3YxAPXaOi0umN5B8E6cXfp 3tN3IXo2iK8pwo8qZkUoBtkO6fupkOqVkk01/YPrJOysXPCsBVaLZjdfrT7MOCku nrSqVhmxb8+E/Aqiij2e1jr/P/RJ498XsbbzQP1kDgdSnk5LuqGPGhlOzxrj+UWW v8eHEOEYMTRM8b+elHIfPc8heg3BgLLBE5r5Fjg==; X-DKIM2-Info: draft=ietf-dkim-dkim2-spec-09; repo=github.com/dkim2wg/interop; date=2026-11-03; sw=lmtpprox; action=mi-m=1; hc=11; hn=cc,content-transfer-encoding,date,feedback-id,from, in-reply-to,message-id,mime-version,references,subject,to; Message-Instance: m=1; h=sha256:ihrWtDCG23E5KnjvUhXQc39Z7Fv0lAI7UVFe7fwJtcE=:AThDYywETaSArET3c3FXLOpDKBDv2g2T1Qx9LrMUhAM=; X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: dmFkZTFRpX9FVF6utO54jseILhtkxM6NmHMKKmtfjtz88uH4zzmEuG/viqgKXnXMGCf1Fl qDhaoMcoe+dDN1e4nZ6uW3TB84oWn9cZbmXaQ3b9nRcEMSOMrdpI8zcupF+upfPKokgFCo 19/NCasCKShYpSqJSNznq4LVcZASvoQBmb1UYAGC15j+bCmHj5XOvfLt5fzCdh3x2YWxaS MEtoPhdmZKTpWSFZDwTpLiH7HC2R8JrezclNcT6RSmiHy52U4T7sh4o7ZRnqC6s0wdpoW0 NdkY0zlCFThtMMhcxOTu8M4oFro+kzrG+gcOBMcZD5flR1/La9uB63EZkckqPtGKdAEAdc mCwHbnBb6+DV9qTSSkAzbWlhBAY9r4UurJeP3/MCGehMpQ9MOXA3Kc85GnXx/qgSlq5uNb W1fOMT0UrjK/C5nm0zUFCkEM6Yr3OHEBWZGE0HzqLY4xyIDTUsWFLVGAI4Qzjxiz7xE/zb 6P8Pk4xNYzNRg4lXyvlQy7mEEFAD3OqE12E15azqVI7AH0wDRz+iyZ2Y5o27umY6MPQSY8 8Fj3DXnqUqlk6SI7bS0ntB9WFvSwJtEoDUd84KQ/KSra99ImegIiOU6skn+txfVntSVYc7 bibvoqBr0Cv+V5+DhrMxdtqBXU+SrdB0Ci/8UzhCov1UitadRX3dGHvjM18A X-ME-Proxy: Feedback-ID: ib53e4b78:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 4 Dec 2026 01:05:06 -0500 (EST) From: Ian Bridges To: Namjae Jeon Cc: Sergey Senozhatsky , Tom Talpey , ChenXiaoSong , linux-cifs@vger.kernel.org, Ian Bridges , stable@vger.kernel.org Subject: [PATCH v3 2/2] ksmbd: keep the durable scavenger until disconnected handles are removed Date: Fri, 4 Dec 2026 00:04:42 -0600 Message-ID: <20261204060442.30849-3-icb@fastmail.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261204060442.30849-1-icb@fastmail.org> References: <20261204060442.30849-1-icb@fastmail.org> 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 The durable handle scavenger removes a disconnected durable handle when its timeout ends. There are three ways the scavenger can stop or sleep while such a handle is still waiting. A lookup, such as a reconnect, holds a reference on the handle while the lookup runs. The scavenger skips a handle with more than one reference. If the scavenger skips every handle in a pass, the scavenger stops. When the reconnect then fails, nothing removes the expired handle until another disconnect starts the scavenger. Until then the handle keeps its share access, byte-range locks and lease. A disconnect that finds the scavenger running does not wake the scavenger. If the scavenger is waiting for the deadline of another handle, the new handle stays past its own timeout until that wait ends. The scavenger clears durable_scavenger_running without durable_scavenger_lock when the scavenger stops. A disconnect in that window finds the scavenger still running and does not start a new one, so the handle of that disconnect is not removed at all. Count a held handle as waiting, and check an expired held handle again a second later. When a disconnect finds the scavenger running, wake the scavenger. Before the scavenger stops, check under durable_scavenger_lock whether such a disconnect came in, and if one did, run another pass. Fixes: d484d621d40f ("ksmbd: add durable scavenger timer") Cc: stable@vger.kernel.org Signed-off-by: Ian Bridges --- fs/smb/server/vfs_cache.c | 89 ++++++++++++++++++++++++++++++++++----- 1 file changed, 78 insertions(+), 11 deletions(-) diff --git a/fs/smb/server/vfs_cache.c b/fs/smb/server/vfs_cache.c index 6bb35d95d495..373a619530f9 100644 --- a/fs/smb/server/vfs_cache.c +++ b/fs/smb/server/vfs_cache.c @@ -265,6 +265,13 @@ static int create_proc_files(void) { return 0; } #endif static bool durable_scavenger_running; +/* + * Set when a disconnect finds the scavenger thread already started. The thread + * may be asleep until the deadline of another handle, so the disconnect sets + * this flag and wakes the thread. The thread then runs a pass that sees the + * newly disconnected handle, and does not stop before that pass. + */ +static bool durable_scavenger_launched; static DEFINE_MUTEX(durable_scavenger_lock); static wait_queue_head_t dh_wq; @@ -1860,6 +1867,35 @@ static bool tree_conn_fd_check(struct ksmbd_tree_connect *tcon, return fp->tcon != tcon; } +/* How soon the scavenger looks again at an expired handle that is held */ +#define DURABLE_SCAVENGER_RETRY_MS 1000 + +/* + * Called when the scavenger is about to stop. Return true when a disconnect + * found the scavenger running since its last pass. That disconnect did not + * start a new scavenger, so this scavenger runs another pass for the handle + * that the disconnect left. Otherwise mark the scavenger stopped and return + * false. + * + * A disconnect takes durable_scavenger_lock too. A disconnect before this + * check has set durable_scavenger_launched, which this check sees. A + * disconnect after this check finds the scavenger stopped and starts a new + * one. + */ +static bool ksmbd_durable_scavenger_rerun(void) +{ + bool rerun; + + mutex_lock(&durable_scavenger_lock); + rerun = durable_scavenger_running && durable_scavenger_launched && + !kthread_should_stop(); + durable_scavenger_launched = false; + if (!rerun) + durable_scavenger_running = false; + mutex_unlock(&durable_scavenger_lock); + return rerun; +} + static bool ksmbd_durable_scavenger_alive(void) { if (!durable_scavenger_running) @@ -1910,18 +1946,37 @@ static int ksmbd_durable_scavenger(void *dummy) __module_get(THIS_MODULE); set_freezable(); +again: while (ksmbd_durable_scavenger_alive()) { if (try_to_freeze()) continue; remaining_jiffies = wait_event_interruptible_timeout(dh_wq, - ksmbd_durable_scavenger_alive() == false, + ksmbd_durable_scavenger_alive() == false || + READ_ONCE(durable_scavenger_launched), __msecs_to_jiffies(min_timeout)); if ((long)remaining_jiffies > 0) min_timeout = jiffies_to_msecs(remaining_jiffies); else min_timeout = DURABLE_HANDLE_MAX_TIMEOUT; + /* + * Clear durable_scavenger_launched before the pass. The pass + * scans every handle in the table, so the pass covers the + * disconnects that set the flag so far. A disconnect on another + * thread can set the flag again while the pass runs, in + * ksmbd_launch_ksmbd_durable_scavenger(), and the handle of + * that disconnect may come too late for the pass. If the + * scavenger goes on, the wait at the top of this loop sees the + * flag in its condition and ends at once. If the scavenger is + * about to stop, ksmbd_durable_scavenger_rerun() sees the flag, + * and the scavenger runs another pass instead of stopping. + * Without the clear, that wait would end at once every time. + */ + mutex_lock(&durable_scavenger_lock); + durable_scavenger_launched = false; + mutex_unlock(&durable_scavenger_lock); + do { expired_fp = NULL; found_fp_timeout = false; @@ -1931,17 +1986,20 @@ static int ksmbd_durable_scavenger(void *dummy) unsigned long durable_timeout; u64 now; - if (!fp->durable_timeout) - continue; - - if (atomic_read(&fp->refcount) > 1 || - fp->conn) + if (!fp->durable_timeout || fp->conn) continue; + /* + * A disconnected handle that a lookup holds + * still waits for its timeout. Count it, so + * that the scavenger does not stop and leave + * it behind. + */ found_fp_timeout = true; now = get_jiffies_64(); if (time_after_eq64(now, - fp->durable_scavenger_timeout)) { + fp->durable_scavenger_timeout) && + atomic_read(&fp->refcount) == 1) { __ksmbd_remove_durable_fd(fp); /* * Take a transient reference so fp @@ -1957,9 +2015,13 @@ static int ksmbd_durable_scavenger(void *dummy) break; } - durable_timeout = - jiffies64_to_msecs(fp->durable_scavenger_timeout - - now); + if (time_after_eq64(now, + fp->durable_scavenger_timeout)) + durable_timeout = DURABLE_SCAVENGER_RETRY_MS; + else + durable_timeout = + jiffies64_to_msecs(fp->durable_scavenger_timeout - + now); if (min_timeout > durable_timeout) min_timeout = durable_timeout; @@ -1974,7 +2036,10 @@ static int ksmbd_durable_scavenger(void *dummy) break; } - durable_scavenger_running = false; + if (ksmbd_durable_scavenger_rerun()) { + min_timeout = 1; + goto again; + } module_put(THIS_MODULE); @@ -1988,6 +2053,8 @@ void ksmbd_launch_ksmbd_durable_scavenger(void) mutex_lock(&durable_scavenger_lock); if (durable_scavenger_running == true) { + durable_scavenger_launched = true; + wake_up(&dh_wq); mutex_unlock(&durable_scavenger_lock); return; } -- 2.47.3