Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 15F401D7E5C for ; Mon, 3 Nov 2025 15:44:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762184665; cv=none; b=FIGZ6GL+JtFwWzC/ePmjB/0iM3oBqYqFTf/OvSQ01iOzSd0nu0grnvTiqtdw07rWhq/saSkRAjDP4b/KXiFHre9m0rGmqgDfOGoWUtL7LfX33ISSQMUf3GcQPvjdtlZZURxv/g4TeN+CNQfEW110DzJjtp5u+I2pxB4mwybMem0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762184665; c=relaxed/simple; bh=5EeucuL/sJ/IG6IrztqIl2doZf+61omofGHCMXJCHLM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=F3WREAaRVRjqKBT0mdLkOWbGO/zj7p1Ysl9rM7mzQOX0XJ4IwnW1Wh7HFSvZ3iSlzS6VkuKA0atv7uXX1eZY/o7MrI3k9pF/0S9rUvk4KS4D195l0pl+eFZc5qcTh6x9ZiHyUBI+t05X8wgmYaP5y0uaVWMElbFBqPgBVd/HWNE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=c/312jEW; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="c/312jEW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1762184663; 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=Zsi7d2maywzB5M6PbzXlkog5Ophmf7hGwvl+CQEzdeQ=; b=c/312jEW85Q8icPHo2egCPTRp0ztcvnuv6MaougK7IFGFB6za8/yctS0NTpl45VhR74NaC ebVZM1VccJhOPfdLMvIRkM/3+D+p7c8lr49LULVUjtas+I7QO6egoU6RKf6AHgwg2Ho/fN /80GQOPX6616oT+TVXlFwEHhT5xdDzE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-227-ycYoPqyjNHG9HcN-mJj9HQ-1; Mon, 03 Nov 2025 10:44:19 -0500 X-MC-Unique: ycYoPqyjNHG9HcN-mJj9HQ-1 X-Mimecast-MFC-AGG-ID: ycYoPqyjNHG9HcN-mJj9HQ_1762184658 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 56B89180120B; Mon, 3 Nov 2025 15:44:18 +0000 (UTC) Received: from aion.redhat.com (unknown [10.22.88.126]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1DA0130001A1; Mon, 3 Nov 2025 15:44:17 +0000 (UTC) Received: from aion.redhat.com (localhost [IPv6:::1]) by aion.redhat.com (Postfix) with ESMTP id EC2AA4E123D; Mon, 03 Nov 2025 10:44:15 -0500 (EST) From: Scott Mayhew To: trondmy@kernel.org, anna@kernel.org Cc: bcodding@hammerspace.com, linux-nfs@vger.kernel.org Subject: [PATCH v2] NFSv4: ensure the open stateid seqid doesn't go backwards Date: Mon, 3 Nov 2025 10:44:15 -0500 Message-ID: <20251103154415.1776520-1-smayhew@redhat.com> Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 We have observed an NFSv4 client receiving a LOCK reply with a status of NFS4ERR_OLD_STATEID and subsequently retrying the LOCK request with an earlier seqid value in the stateid. As this was for a new lockowner, that would imply that nfs_set_open_stateid_locked() had updated the open stateid seqid with an earlier value. Looking at nfs_set_open_stateid_locked(), if the incoming seqid is out of sequence, the task will sleep on the state->waitq for up to 5 seconds. If the task waits for the full 5 seconds, then after finishing the wait it'll update the open stateid seqid with whatever value the incoming seqid has. If there are multiple waiters in this scenario, then the last one to perform said update may not be the one with the highest seqid. Add a check to ensure that the seqid can only be incremented, and add a tracepoint to indicate when old seqids are skipped. Signed-off-by: Scott Mayhew --- v2: Move the new check so that it's only being done for tasks that have waited the full 5 seconds. That way the common case isn't calling nfs4_stateid_match_other() twice. fs/nfs/nfs4proc.c | 13 +++++++++++-- fs/nfs/nfs4trace.h | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c index 411776718494..04005dbfb905 100644 --- a/fs/nfs/nfs4proc.c +++ b/fs/nfs/nfs4proc.c @@ -1780,8 +1780,17 @@ static void nfs_set_open_stateid_locked(struct nfs4_state *state, if (nfs_stateid_is_sequential(state, stateid)) break; - if (status) - break; + if (status) { + if (nfs4_stateid_match_other(stateid, &state->open_stateid) && + !nfs4_stateid_is_newer(stateid, &state->open_stateid)) { + trace_nfs4_open_stateid_update_skip(state->inode, + stateid, status); + return; + } else { + break; + } + } + /* Rely on seqids for serialisation with NFSv4.0 */ if (!nfs4_has_session(NFS_SERVER(state->inode)->nfs_client)) break; diff --git a/fs/nfs/nfs4trace.h b/fs/nfs/nfs4trace.h index 9776d220cec3..6285128e631a 100644 --- a/fs/nfs/nfs4trace.h +++ b/fs/nfs/nfs4trace.h @@ -1353,6 +1353,7 @@ DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_setattr); DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_delegreturn); DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_open_stateid_update); DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_open_stateid_update_wait); +DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_open_stateid_update_skip); DEFINE_NFS4_INODE_STATEID_EVENT(nfs4_close_stateid_update_wait); DECLARE_EVENT_CLASS(nfs4_getattr_event, -- 2.51.0