Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4813991yba; Tue, 30 Apr 2019 04:57:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqy3UNC/7oumWHwId6cAyFhZfkm02EdYF/0KyMT23CuKYyebo+GJZS1x974kwoTHoky6bl00 X-Received: by 2002:a65:6091:: with SMTP id t17mr5915514pgu.328.1556625478576; Tue, 30 Apr 2019 04:57:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556625478; cv=none; d=google.com; s=arc-20160816; b=P0Ftw4150kY4WM65mxRMptSlsssxhH+S8BO6o4YG33k28XesWb/t0Yr7H5q1PeKZ8b PcNGkL8EANXKRpWyrbbm4OIKO5yMvxfFjjm5Kr+3VAL4ZDqbNnM536PxH6BTZsUboyuw +yvFVerrfA17ouBDEehKRiXCCwqKP0cABwV7BlwWu6B0JI2bNRk7wl+H+vh1WLpCv9yR f9GASwhpK/Ja/mLk5TB0x4mARfsQKVf94+mPasguYERqb/LYKeOEqhgU31xntwST8IRX AkCrK6Qk3Xj57p6fqwlmhEUcGKSX3acpzlvDjU3DHc+4mw8Mm5C4YsXjTe8W7JAADiMN Z5AQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xgF6RGq8eE6FZeohpaWiGt32hI6p+8ZToKfSYuhvOMA=; b=fbozX6ZpO1eHRkFyNqbu1MLmaJ49T9BZzCHWL+mLzNemyx+2oItr7Bz1VVDg2vLhcy p9kEn2ia+QpTIfJd3hMZCLW4bc0TRDQ/MX5V8uyvJf77NgDJZOxKkhw9AwEQ1XkHblwc XZtgxiXS6ahPBYmcLYezbWodXcHIB3Y+oeEmjvWOnjTIDcX1z7qLnkuDFwKREcMcEJny 0zffwyo9wUUxrSW34WseCo1iF/2lOwVkeYk7/jhaUTlxyLCTbcCPxFDP6NUYTNBb9BYX 6UsIz9xKcfQhqFwXHmvUg0cI+ZYDET/VMPIfJ/wAlICCEj4tVvRrbAVg8NmR2vG7uqq/ XNHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CqiLbPE0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v3si35625457pga.354.2019.04.30.04.57.43; Tue, 30 Apr 2019 04:57:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CqiLbPE0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726715AbfD3L4I (ORCPT + 99 others); Tue, 30 Apr 2019 07:56:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:35408 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730216AbfD3LtC (ORCPT ); Tue, 30 Apr 2019 07:49:02 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 58BDC20449; Tue, 30 Apr 2019 11:49:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556624941; bh=XZj4mr16NFVkMu39V8QqgpX0TDjBG2kL9Yj3vw4Dj2k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CqiLbPE0HnYkN3iFjpv2ePvNY/kAjFejJQXrAEnhrTlrneiePLIefqjj57+f/N5qO LOPGzXvG6fPD7XaqoUBJp/p+qBjuL48IyUfC6MN7GeF++/1iv39kBOVnLoCn2vrSYE eF/1fE49N0GzbUMkOrPfA41K770ZngBqvl0NUNuM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Trond Myklebust , "J. Bruce Fields" Subject: [PATCH 5.0 30/89] nfsd: Dont release the callback slot unless it was actually held Date: Tue, 30 Apr 2019 13:38:21 +0200 Message-Id: <20190430113611.349597939@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190430113609.741196396@linuxfoundation.org> References: <20190430113609.741196396@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Trond Myklebust commit e6abc8caa6deb14be2a206253f7e1c5e37e9515b upstream. If there are multiple callbacks queued, waiting for the callback slot when the callback gets shut down, then they all currently end up acting as if they hold the slot, and call nfsd4_cb_sequence_done() resulting in interesting side-effects. In addition, the 'retry_nowait' path in nfsd4_cb_sequence_done() causes a loop back to nfsd4_cb_prepare() without first freeing the slot, which causes a deadlock when nfsd41_cb_get_slot() gets called a second time. This patch therefore adds a boolean to track whether or not the callback did pick up the slot, so that it can do the right thing in these 2 cases. Cc: stable@vger.kernel.org Signed-off-by: Trond Myklebust Signed-off-by: J. Bruce Fields Signed-off-by: Greg Kroah-Hartman --- fs/nfsd/nfs4callback.c | 8 +++++++- fs/nfsd/state.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) --- a/fs/nfsd/nfs4callback.c +++ b/fs/nfsd/nfs4callback.c @@ -1023,8 +1023,9 @@ static void nfsd4_cb_prepare(struct rpc_ cb->cb_seq_status = 1; cb->cb_status = 0; if (minorversion) { - if (!nfsd41_cb_get_slot(clp, task)) + if (!cb->cb_holds_slot && !nfsd41_cb_get_slot(clp, task)) return; + cb->cb_holds_slot = true; } rpc_call_start(task); } @@ -1051,6 +1052,9 @@ static bool nfsd4_cb_sequence_done(struc return true; } + if (!cb->cb_holds_slot) + goto need_restart; + switch (cb->cb_seq_status) { case 0: /* @@ -1089,6 +1093,7 @@ static bool nfsd4_cb_sequence_done(struc cb->cb_seq_status); } + cb->cb_holds_slot = false; clear_bit(0, &clp->cl_cb_slot_busy); rpc_wake_up_next(&clp->cl_cb_waitq); dprintk("%s: freed slot, new seqid=%d\n", __func__, @@ -1296,6 +1301,7 @@ void nfsd4_init_cb(struct nfsd4_callback cb->cb_seq_status = 1; cb->cb_status = 0; cb->cb_need_restart = false; + cb->cb_holds_slot = false; } void nfsd4_run_cb(struct nfsd4_callback *cb) --- a/fs/nfsd/state.h +++ b/fs/nfsd/state.h @@ -70,6 +70,7 @@ struct nfsd4_callback { int cb_seq_status; int cb_status; bool cb_need_restart; + bool cb_holds_slot; }; struct nfsd4_callback_ops {