Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp9044937pxu; Mon, 28 Dec 2020 05:17:20 -0800 (PST) X-Google-Smtp-Source: ABdhPJzccUF/SboXj4MmxDRkG+hts/iu0TGb8lECa0/kadnl5O2OzxhoEdXBp1w9PF3IqWSo/+mp X-Received: by 2002:a05:6402:1c8a:: with SMTP id cy10mr42216461edb.151.1609161439882; Mon, 28 Dec 2020 05:17:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1609161439; cv=none; d=google.com; s=arc-20160816; b=IQfGXBaWpoXQI4wtQ7RT/hsltHZpZZmk79nOq2gub706mFWr+QGvIqNne39X2fa5C5 gF2lRmu4jSBe5LXVCLcE9ywtLM8VyHJ9hBP5Qcyb2GI3qY4AqDaH60WpumQDlCI+Q02d DwCHcba8XZIl/0qr2zuL2IG87r3370fxv9lvCTwi97DShoPyS2NZlIzggx3Y3ReY+GrZ RZ8weVslr2/d+dzddisij3TecHkwR9e1f+VbNhLVBoQqlxe4Jvbh8OZwGWX72+lR5kFV 5t0Xpbs8bFNFcqm6CsLnjhxkEXJnkAUmekusZzVcEi9dmeAWiFaa1Ph9sHU9DyDQvHgU bCqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=85edGUfK66iCpzamNCXqTA3duqN0m7JAZTm2Ld02mzo=; b=NJbxDgkBFIKZm4nROMEF0ImqBJ1wOmGpW5L+tTJKgwnhlCeDZ9L0TBFmMW6sUCPjwp FhV+9T2hXtGtuxrikkP7ySjqTY4cp2Kiji8yf0+/U6UOah4kNj81qSm7jbW54vQiLE6r r+dqOm02acYs9QhHUMjI5Has306JDZKgjhplGum/Sq+EQEJ0fKbdoS+rQ2RV/pVlNSjG Zcx+mq6oL3fHLu1JMdXTyUoJHkwqE/OTUdXqgLkScFHxx+vruzwnY3vHT5Lv49dCY1uC Q5I99ZcVzaz4TTbPx4G0DWC9Rit8fZSBI13VWakOUk0f8dBbr2Zc8kaK7Ouh/7YSOfF0 U0hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2mCJfMKy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k10si20476930eds.206.2020.12.28.05.16.57; Mon, 28 Dec 2020 05:17:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2mCJfMKy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732599AbgL1NO7 (ORCPT + 99 others); Mon, 28 Dec 2020 08:14:59 -0500 Received: from mail.kernel.org ([198.145.29.99]:43030 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732583AbgL1NOx (ORCPT ); Mon, 28 Dec 2020 08:14:53 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 812F7207C9; Mon, 28 Dec 2020 13:14:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1609161253; bh=5edn3WqNlmk3g3uK+pzaKXVoJ9oJ7VprZO77+CHT69c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2mCJfMKyk0hYtj9sA5G9iMcoNotKtQBQYjOG7EvbD+LiaYqenOEG5ZOq0N9O/xLtj UsvHXqaO+iGOD2OrKH+cbHeZlfGRJ1X2RT/V8dH9xbxnq+9r2pR2SVwRaDv0GO/j05 ywd47Dou22AIAMtB6OKiZqztG5sjQLm/8EpAm/Pk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?=C2=A0Cheng=C2=A0Lin=C2=A0?= , =?UTF-8?q?=C2=A0Yi=C2=A0Wang=C2=A0?= , Chuck Lever , Sasha Levin Subject: [PATCH 4.14 154/242] nfs_common: need lock during iterate through the list Date: Mon, 28 Dec 2020 13:49:19 +0100 Message-Id: <20201228124912.285004439@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201228124904.654293249@linuxfoundation.org> References: <20201228124904.654293249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Cheng Lin [ Upstream commit 4a9d81caf841cd2c0ae36abec9c2963bf21d0284 ] If the elem is deleted during be iterated on it, the iteration process will fall into an endless loop. kernel: NMI watchdog: BUG: soft lockup - CPU#4 stuck for 22s! [nfsd:17137] PID: 17137  TASK: ffff8818d93c0000  CPU: 4   COMMAND: "nfsd"     [exception RIP: __state_in_grace+76]     RIP: ffffffffc00e817c  RSP: ffff8818d3aefc98  RFLAGS: 00000246     RAX: ffff881dc0c38298  RBX: ffffffff81b03580  RCX: ffff881dc02c9f50     RDX: ffff881e3fce8500  RSI: 0000000000000001  RDI: ffffffff81b03580     RBP: ffff8818d3aefca0   R8: 0000000000000020   R9: ffff8818d3aefd40     R10: ffff88017fc03800  R11: ffff8818e83933c0  R12: ffff8818d3aefd40     R13: 0000000000000000  R14: ffff8818e8391068  R15: ffff8818fa6e4000     CS: 0010  SS: 0018  #0 [ffff8818d3aefc98] opens_in_grace at ffffffffc00e81e3 [grace]  #1 [ffff8818d3aefca8] nfs4_preprocess_stateid_op at ffffffffc02a3e6c [nfsd]  #2 [ffff8818d3aefd18] nfsd4_write at ffffffffc028ed5b [nfsd]  #3 [ffff8818d3aefd80] nfsd4_proc_compound at ffffffffc0290a0d [nfsd]  #4 [ffff8818d3aefdd0] nfsd_dispatch at ffffffffc027b800 [nfsd]  #5 [ffff8818d3aefe08] svc_process_common at ffffffffc02017f3 [sunrpc]  #6 [ffff8818d3aefe70] svc_process at ffffffffc0201ce3 [sunrpc]  #7 [ffff8818d3aefe98] nfsd at ffffffffc027b117 [nfsd]  #8 [ffff8818d3aefec8] kthread at ffffffff810b88c1  #9 [ffff8818d3aeff50] ret_from_fork at ffffffff816d1607 The troublemake elem: crash> lock_manager ffff881dc0c38298 struct lock_manager {   list = {     next = 0xffff881dc0c38298,     prev = 0xffff881dc0c38298   },   block_opens = false } Fixes: c87fb4a378f9 ("lockd: NLM grace period shouldn't block NFSv4 opens") Signed-off-by: Cheng Lin  Signed-off-by: Yi Wang  Signed-off-by: Chuck Lever Signed-off-by: Sasha Levin --- fs/nfs_common/grace.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/nfs_common/grace.c b/fs/nfs_common/grace.c index 3b13fb3b05530..63c9c2a70937f 100644 --- a/fs/nfs_common/grace.c +++ b/fs/nfs_common/grace.c @@ -75,10 +75,14 @@ __state_in_grace(struct net *net, bool open) if (!open) return !list_empty(grace_list); + spin_lock(&grace_lock); list_for_each_entry(lm, grace_list, list) { - if (lm->block_opens) + if (lm->block_opens) { + spin_unlock(&grace_lock); return true; + } } + spin_unlock(&grace_lock); return false; } -- 2.27.0