From patchwork Thu Jun 26 19:12:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 4430891 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 682DABEEAA for ; Thu, 26 Jun 2014 19:15:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87CB1201BB for ; Thu, 26 Jun 2014 19:15:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8B8112024D for ; Thu, 26 Jun 2014 19:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751623AbaFZTPf (ORCPT ); Thu, 26 Jun 2014 15:15:35 -0400 Received: from mail-qa0-f44.google.com ([209.85.216.44]:49440 "EHLO mail-qa0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750986AbaFZTPd (ORCPT ); Thu, 26 Jun 2014 15:15:33 -0400 Received: by mail-qa0-f44.google.com with SMTP id hw13so3223263qab.31 for ; Thu, 26 Jun 2014 12:15:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=8G2k4HaCANJHwHg/5lfwBkVoYQaJXpkHRpYX0XaggiY=; b=SNzrebpX2rfO4ahWDK398/LiVHGcLdJUKmZc/GItUgOIB0571z1mZ8oUQcB1K+P6ci POA1WQHMidZRUtcknKcBIujtJKOvgEikRG51nfPM6CaCNQt593NDEWhJQoy0XL2/h+Dt AmCtgFrmO5bY71CIoYkdn/IsgxGH7Emgo434MZRLdX5dJNYnGjLfU4ipBfRBiH9Y71Ge ZowfSWHUn7Mf6vF8U8PQTCoQfXJxCM9wJWYbxSSTGAMnQdJoVbcTRYBBk9fpJv9R4AIe VlNumVQ3JhkeQycEjQoWtEc3Jl6bLO97lZfQONcFW9/xMjSFEZHpTCqOKBbB5/b9pI7N +93w== X-Gm-Message-State: ALoCoQlZPcF3PS832ojqS2Csfg8qaqimXUkbB8KHgLoGgKwjlUCz4SjxLn76Q6O+SLl0de+wz6Ce X-Received: by 10.224.68.2 with SMTP id t2mr25785679qai.71.1403810133293; Thu, 26 Jun 2014 12:15:33 -0700 (PDT) Received: from tlielax.poochiereds.net ([2001:470:8:d63:3a60:77ff:fe93:a95d]) by mx.google.com with ESMTPSA id 88sm4763039qgh.5.2014.06.26.12.15.31 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jun 2014 12:15:32 -0700 (PDT) From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 079/117] nfsd: don't thrash the cl_lock while freeing an open stateid Date: Thu, 26 Jun 2014 15:12:59 -0400 Message-Id: <1403810017-16062-80-git-send-email-jlayton@primarydata.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> References: <1403810017-16062-1-git-send-email-jlayton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When we remove the client_mutex, we'll have a potential race between FREE_STATEID and CLOSE. The root of the problem is that we are walking the st_locks list, dropping the spinlock and then trying to release the persistent reference to the lockstateid. In between, a FREE_STATEID call can come along and take the lock, find the stateid and then try to put the reference. That leads to a double put. Fix this by not releasing the cl_lock in order to release each lock stateid. Use put_generic_stateid_locked to unhash them and gather them onto a list, and free_stateid_reaplist to free any that end up on the list. Signed-off-by: Jeff Layton --- fs/nfsd/nfs4state.c | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 60dc6b4921dd..ca87362b9a17 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -1032,27 +1032,26 @@ static void release_lockowner(struct nfs4_lockowner *lo) nfs4_put_stateowner(&lo->lo_owner); } -static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp) - __releases(&open_stp->st_stateowner->so_client->cl_lock) - __acquires(&open_stp->st_stateowner->so_client->cl_lock) +static void release_open_stateid_locks(struct nfs4_ol_stateid *open_stp, + struct list_head *reaplist) { struct nfs4_ol_stateid *stp; while (!list_empty(&open_stp->st_locks)) { stp = list_entry(open_stp->st_locks.next, struct nfs4_ol_stateid, st_locks); - spin_unlock(&open_stp->st_stateowner->so_client->cl_lock); - release_lock_stateid(stp); - spin_lock(&open_stp->st_stateowner->so_client->cl_lock); + unhash_lock_stateid(stp); + put_generic_stateid_locked(stp, reaplist); } } -static void unhash_open_stateid(struct nfs4_ol_stateid *stp) +static void unhash_open_stateid(struct nfs4_ol_stateid *stp, + struct list_head *reaplist) { lockdep_assert_held(&stp->st_stateowner->so_client->cl_lock); unhash_generic_stateid(stp); - release_open_stateid_locks(stp); + release_open_stateid_locks(stp, reaplist); } static void unhash_openowner_locked(struct nfs4_openowner *oo) @@ -1089,7 +1088,7 @@ static void release_openowner(struct nfs4_openowner *oo) while (!list_empty(&oo->oo_owner.so_stateids)) { stp = list_first_entry(&oo->oo_owner.so_stateids, struct nfs4_ol_stateid, st_perstateowner); - unhash_open_stateid(stp); + unhash_open_stateid(stp, &reaplist); put_generic_stateid_locked(stp, &reaplist); } spin_unlock(&clp->cl_lock); @@ -4670,16 +4669,21 @@ out: static void nfsd4_close_open_stateid(struct nfs4_ol_stateid *s) { struct nfs4_client *clp = s->st_stid.sc_client; + LIST_HEAD(reaplist); s->st_stid.sc_type = NFS4_CLOSED_STID; spin_lock(&clp->cl_lock); - unhash_open_stateid(s); - spin_unlock(&clp->cl_lock); + unhash_open_stateid(s, &reaplist); - if (clp->cl_minorversion) - put_generic_stateid(s); - else + if (clp->cl_minorversion) { + put_generic_stateid_locked(s, &reaplist); + spin_unlock(&clp->cl_lock); + free_stateid_reaplist(&reaplist); + } else { + spin_unlock(&clp->cl_lock); + free_stateid_reaplist(&reaplist); move_to_close_lru(s, clp->net); + } } /*