Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.138 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796288155; b=z7cD/q2iuVWcbt8i0llYyMBLMvRS+6Y0wl4Wp/bHYm4xaWhCxLcsvnoGz6rftoHWISGf Qc92SlI69cxgDkFusfO0ik49cy9d9ch5OxKKp6G7D/HXO6Rf7J/6hBPUC4T81Mo4JBcEK o+Jbl/1v15kTuvNae6YmNuCT8txPf3VOF6GSSapvMc5mJsPRxB55rBNHpE5EpxsgF0CQ0 rpUTioZ9HpSyl/S/Wf5VCNzNAGQt/gYDGiFkRxtIVa7i1fUtcNssIQALatO5idqcRn9CJ mKSTP+oIzi9JpUuRsbuGauQH6jPiqI3rNSxkWbQALW0RzMCYsAhME/Ikq+0Jl7AsiHw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796288155; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Date:From:To:Cc: Subject:Message-ID:MIME-Version:Content-Type:Content-Disposition: X-Mailer; bh=nE7PWOWvkSUllplhg69rH2VCGajPxh1OLgj+fcwrxmo=; b=Je2sj8g50/8k7Sh/FdtD1wWsh3gj3HAgp7y51PNp1xNyTNY/BobfVcKdVSJ0cnC10aus eYgiIfWlE033TiPo5GFNrdTvWKUAHKoEDRe9X+rD5ni3mZEsM68OGbQGD2pvbaKpJ1b2I Vrj1daAEL/kxAFtd0ZLLy9IoZ7gWQoSthVC4uRUJFa+TYACfBSTkVrev5u85Sl3JiQxbI OmCIoQGtzFFFXnZpBUz3NhddfrjY3TI5rvp83DxhVfirZ+i832JxdSZXq0X4E8F0rTL9H KsVVAH8TWNOfCC9Jda2eGGe68gEMgjFb2uRpoYEAPggw9u897Xg2zbuLejKiLv3UZbA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hY3gUxaT; arc=none smtp.remote-ip=74.125.227.138 Received: from mail-pj2-f10.google.com (mail-pj2-f10.google.com [74.125.227.138]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 725E5606A322 for ; Thu, 3 Dec 2026 08:55:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 725E5606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=hY3gUxaT Received: by mail-pj2-f10.google.com with SMTP id 98e67ed59e1d1-3b3bbd46625so3992899a91.1 for ; Thu, 03 Dec 2026 00:55:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796288155; x=1796892955; darn=vger.kernel.org; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=nE7PWOWvkSUllplhg69rH2VCGajPxh1OLgj+fcwrxmo=; b=hY3gUxaTi8V4X/QJ1UswQSGfn585WA0BMfe7+W9FOqlujAUd+Mhte+RmKXFP7peVzj x1qhwV4xM+mhcCxB6kRRYaEuvg2KflhElAG4wlwHRDHCRy9W2NmBJpQ0V4J9Acnqulk0 s921pM622R6QInJqPZJHcYQwf4OVYqqfrk75nSgjzEGFEYpHwXBcHS/L4NN9We1cjWuA skm6y0x9C6jVi3Bhwv5gHA1OEWqE4TvMB40VLPpfNYAHj2oNhJDqN8wRky6zFUA/KaYS 13PBjrfAhxcsqurZx0V8uwIFQAh6ffX5+Q2ulU1Pv4J7coCOlmQ+p/AzdXFDzk5HuAH/ JEgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796288155; x=1796892955; h=content-disposition:content-type:mime-version:message-id:subject:cc :to:from:date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nE7PWOWvkSUllplhg69rH2VCGajPxh1OLgj+fcwrxmo=; b=F4xyLxlz8e2zamO0rH6ReZNaorKzYW+vvAvvp8Lg/C4ubyplCAr/weWAtYHAxyS12i 0nT9401TjD8//75q4S50JRzp58PedaPGFKUfFFUwKZrqbAglQbO9WIcBzK+SnsqO84Z5 rNgxBXdanIJC66m6nN1MzQRRxTH7jFs+3olv/kGkLA0+tHES19SsEJStZexvqC8yZxkg tlB7O67+ONu+s3iiorqbx4jLLmhpIWDE5EkjEewe+8wAsEo8AOaPnV2GbhX3WH3k307o m7ZZL9wIdlEMECGGdNqjpkZP7j4MvfKgpVrpmWh7YnT8eRFbHllIx1TP2HSSRR1UeAkp bAFg== X-Gm-Message-State: APuU4Z9fwnEWxXQL8jYSun6xiO2jO4WVQfcZfCmvHrs98WQIaJcgRZZE cT3sqszutM7jp+7xGrFw0Rfn4nrE4ghmCvh3UlTSQCE5bXfM51TmwJoa X-Gm-Gg: AZFdTZfAhowhEGEpamKihSXd+9pxZWCBx+FBpgLutYgeQguMNckF1iC2IP/UcmeVw3I p0XDmabh33yH5xl2jehjKuaqIGroyn2Kf+LCeSQbFGv4ROM4XJZpqYyNsN5SbGcBzlTCjS2zXKO 5QHAQNfrCG5ok281afRNg1rYutaGl4X7JnJYsPZAk6Y36zrT/9PU7jKsezQShvQkuInDjMqqXXf 2F3BS2PuJnBT1YuG9KC9heHq7mo1aTBzKWsUSss0aactcw6IJyN7RI8vzlIQVMNJb0NQeadcZFZ fRmoFdlf1mvMYtQjGGPuWK6RnkTDx2Jlb+4ZCVZcPjQrf/K/3ktUBXjYcOW0U2YAZtc9/+lLtIR /PYg0GYdUeH65/aUizz2GDbkNH4Tx0fJ3ltpxJYsQFkPZpvRpfgZac+zTtmIu4gGxPmOC2Af5Zk bfF0b2J44o9b2ndZ6vyTxcNMm6ycJ7dvotknJbB48X10SkVyxKsXcD1YwgFT+x/O6hSz2tREzEX exc9htssi5kuotWFCAlsv+2CmtzCU5hzv8wroyhWXG1A8pay09uczaVVxGNOCt82afAIATRAHtN LiT7tVI/mDL54FzT8g7+VBXiM5fI14QiVSkFIROK X-Received: by 2002:a17:90a:e7d0:b0:3b1:8396:ebf8 with SMTP id 98e67ed59e1d1-3b41c9325bcmr40807931a91.36.1796288154750; Thu, 03 Dec 2026 00:55:54 -0800 (PST) Received: from hhost ([120.231.212.214]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c78641bdsm3379855a91.9.2026.12.03.00.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Dec 2026 00:55:53 -0800 (PST) Date: Thu, 3 Dec 2026 16:55:46 +0800 From: Xingyuan Mo To: Trond Myklebust , Anna Schumaker Cc: "open list:NFS, SUNRPC, AND LOCKD CLIENTS" , Xingyuan Mo , stable@vger.kernel.org Subject: [PATCH] NFSv4: Fix nr_active_delegations underflow on a duplicate delegation Message-ID: <20261203085534.2255439-1-hdthky0@gmail.com> X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Mailer: git-send-email 2.43.0 When an OPEN reply grants a delegation whose stateid "other" differs from the live delegation on the inode, and it is not an upgrade to a write delegation, nfs_inode_set_delegation() keeps the old delegation and hands the new one back. It does so by parking the freshly allocated object in @freeme and clearing @delegation, so the exit path runs nfs_do_return_delegation(), nfs_mark_delegation_revoked() and nfs_put_delegation() on it. nfs_mark_delegation_revoked() decrements server->nr_active_delegations whenever NFS_DELEGATION_REVOKED was not set before, but that counter is only incremented for delegations that reach the add_new label. The duplicate object never did, so each such OPEN reply drops the counter by one while the old delegation is still held. After the first one the counter reads zero with a live delegation on the server, and further ones drive it negative. With the counter at zero nfs_delegations_present() tells renewd that no delegations are held, so it no longer sets NFS4_RENEW_DELEGATION_CB for RENEW, and nfs_delegations_over_limit() never trips, so the per-server delegation watermark no longer bounds the delegation cache. The revoked path also clears the delegated dentry verifiers of an inode whose old delegation is still valid. Treat the duplicate like the other delegations the client fails to record: set @orphaned and leave the object in @delegation, so the exit path sends DELEGRETURN and frees it without marking it revoked. @freeme is then only ever the old, counted delegation of the upgrade path. Fixes: d2269ea14ebd2 ("NFSv4: Add accounting for the number of active delegations held") Cc: stable@vger.kernel.org Signed-off-by: Xingyuan Mo --- fs/nfs/delegation.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/nfs/delegation.c b/fs/nfs/delegation.c index ad774316f7166..a9eee4654ffd1 100644 --- a/fs/nfs/delegation.c +++ b/fs/nfs/delegation.c @@ -498,8 +498,7 @@ int nfs_inode_set_delegation(struct inode *inode, const struct cred *cred, __func__, clp->cl_hostname); if (delegation->type == old_delegation->type || !(delegation->type & FMODE_WRITE)) { - freeme = delegation; - delegation = NULL; + orphaned = true; goto out; } if (test_and_set_bit(NFS_DELEGATION_RETURNING, -- 2.43.0