atomic_set(&nn->nfsd_courtesy_clients, 0);
 }
 
+enum rp_lock {
+       RP_UNLOCKED,
+       RP_LOCKED,
+       RP_UNHASHED,
+};
+
 static void init_nfs4_replay(struct nfs4_replay *rp)
 {
        rp->rp_status = nfserr_serverfault;
        rp->rp_buflen = 0;
        rp->rp_buf = rp->rp_ibuf;
-       mutex_init(&rp->rp_mutex);
+       atomic_set(&rp->rp_locked, RP_UNLOCKED);
 }
 
-static void nfsd4_cstate_assign_replay(struct nfsd4_compound_state *cstate,
-               struct nfs4_stateowner *so)
+static int nfsd4_cstate_assign_replay(struct nfsd4_compound_state *cstate,
+                                     struct nfs4_stateowner *so)
 {
        if (!nfsd4_has_session(cstate)) {
-               mutex_lock(&so->so_replay.rp_mutex);
+               wait_var_event(&so->so_replay.rp_locked,
+                              atomic_cmpxchg(&so->so_replay.rp_locked,
+                                             RP_UNLOCKED, RP_LOCKED) != RP_LOCKED);
+               if (atomic_read(&so->so_replay.rp_locked) == RP_UNHASHED)
+                       return -EAGAIN;
                cstate->replay_owner = nfs4_get_stateowner(so);
        }
+       return 0;
 }
 
 void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate)
 
        if (so != NULL) {
                cstate->replay_owner = NULL;
-               mutex_unlock(&so->so_replay.rp_mutex);
+               atomic_set(&so->so_replay.rp_locked, RP_UNLOCKED);
+               wake_up_var(&so->so_replay.rp_locked);
                nfs4_put_stateowner(so);
        }
 }
         * Wait for the refcount to drop to 2. Since it has been unhashed,
         * there should be no danger of the refcount going back up again at
         * this point.
+        * Some threads with a reference might be waiting for rp_locked,
+        * so tell them to stop waiting.
         */
+       atomic_set(&oo->oo_owner.so_replay.rp_locked, RP_UNHASHED);
+       wake_up_var(&oo->oo_owner.so_replay.rp_locked);
        wait_event(close_wq, refcount_read(&s->st_stid.sc_count) == 2);
 
        release_all_access(s);
        clp = cstate->clp;
 
        strhashval = ownerstr_hashval(&open->op_owner);
+retry:
        oo = find_or_alloc_open_stateowner(strhashval, open, cstate);
        open->op_openowner = oo;
        if (!oo)
                return nfserr_jukebox;
-       nfsd4_cstate_assign_replay(cstate, &oo->oo_owner);
+       if (nfsd4_cstate_assign_replay(cstate, &oo->oo_owner) == -EAGAIN) {
+               nfs4_put_stateowner(&oo->oo_owner);
+               goto retry;
+       }
        status = nfsd4_check_seqid(cstate, &oo->oo_owner, open->op_seqid);
        if (status)
                return status;
        trace_nfsd_preprocess(seqid, stateid);
 
        *stpp = NULL;
+retry:
        status = nfsd4_lookup_stateid(cstate, stateid,
                                      typemask, statusmask, &s, nn);
        if (status)
                return status;
        stp = openlockstateid(s);
-       nfsd4_cstate_assign_replay(cstate, stp->st_stateowner);
+       if (nfsd4_cstate_assign_replay(cstate, stp->st_stateowner) == -EAGAIN) {
+               nfs4_put_stateowner(stp->st_stateowner);
+               goto retry;
+       }
 
        status = nfs4_seqid_op_checks(cstate, stateid, seqid, stp);
        if (!status)