Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp759541rdb; Thu, 15 Feb 2024 14:55:41 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUl9S61bIGRDabafgFZ6Wb1OeyQGQJ0eBOAqtj4R6pJt1tZyGSwsZjX58G3X298L8iBl3WBV08DCk9e8A5PX1RloxDtQITvoEtxN6s0wQ== X-Google-Smtp-Source: AGHT+IEZJuDdw/wDcdXTrpoLqrQU4iJb5uKgwMm/mYrE+WSxCl7O4CKKPp4JA2cnaxu3Otr27qEJ X-Received: by 2002:a9d:750a:0:b0:6dd:dd86:ad81 with SMTP id r10-20020a9d750a000000b006dddd86ad81mr3640012otk.14.1708037741566; Thu, 15 Feb 2024 14:55:41 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708037741; cv=pass; d=google.com; s=arc-20160816; b=Js/zOP/3o+rA3Uxlslhj8H50QGgzRsf2LsvoIoAmYUoxgPEGadjoRVA+FyvASxzayv c0klH0/5GbbcAwFf8SdXFToZA6cn6RzZSGqYguxy6WC2uci7TqIA14bE//Irar3ArX/l PYtdApuCYzW0kmwh8Q0idAn7U/AnmhL/+iT4rPEl4xbllQ7MGZNsw2JUJ+c7OD3D5Zn6 91GCp9CQ7pTKBkrEFGGT7F8bH4DWpKjWX+kcqqlBHHUcVQfZdiwkBubm/F9dUs9jB/+F 10phTrU00AXn58ftAfhqXcKFcu85SCHBAR+6dbzTQM0E1/wX6beOIhxfecbsbU8MvlFw 6h3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:references:in-reply-to :message-id:date:to:from:subject:dkim-signature; bh=8dxJ0+EInc6Qr+xGI19AFSf6gVvhKl9CmJvLNlVsSc0=; fh=Mys3y4MwsHRytUQMpdfGBn3oGRYLcLloxNwkFYMYMmg=; b=xekchPuuNNPF5tke4+ziUcFHRdcW/XJernDRjPwnAB8TqyCbfwPppONHYP8Ou4SBwH OKYAklZOSyKevPwXRP+Z0S6NDFqspeBXhp8RJpZW/JM8WB2HmkTyHse9TziSvnMLj4BU BpFXu+0rJZMG8/VqE2/MYqqT1Up5O3dY/XjK6/RrHveGnrSvl0LO4SQLZBaG1INbl2DS BDCfgFDPCQrL9SUD5LCs/Dv+hV7yukhSadlxFmTa6vF3/H8Lnlor9URYjIKnJaZoHGcH xiDb8za1VYnfm5CI4M5XGiacFfsSI1NgCmpLvrYdQMlWgZYRupJOjTt+YRy9cP2qnqRf d81g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iwJs2X+t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-1981-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1981-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m123-20020a632681000000b005dc89485b21si1788819pgm.535.2024.02.15.14.55.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 14:55:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-nfs+bounces-1981-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iwJs2X+t; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-nfs+bounces-1981-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-nfs+bounces-1981-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 20B0D280789 for ; Thu, 15 Feb 2024 22:55:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D3DEF2F30; Thu, 15 Feb 2024 22:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iwJs2X+t" X-Original-To: linux-nfs@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 AEF6B13B2BF for ; Thu, 15 Feb 2024 22:55:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708037739; cv=none; b=lMbwNuvQS0LeJJQFfP6Dz6CUO8fiopYnRkoo8XoezPINuCLlxCdPXCSmzIp11YBW5m3eZqauSVJyy5zTMTk3BQQ/IjoY4eJklHeMVl6UvtxaFFWI3Mz+QYgB+OI/YceupsIGVeEBguykadB8kjKlki7YA3o7xlH3pz21/8G3zsk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708037739; c=relaxed/simple; bh=QLeyHs3xueE6EjPGnnRWIhs2QexL6hddi0ZMopmicXI=; h=Subject:From:To:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Pm/sfhgWn8Jyvz6H8rKs6BMeZIav0Noj77d2xlpqSqlaO+w3QFjdDFNJNpnVyVMrDgWG3BjC88twW9FK9PVMvc8+uA/rNolrkJn3Zs80Z/9a747BjoVxA1ntWrg9XlegDwWJk3J/4uszIzRPz/+ZH+UROn9vT25rm7umZoaRblQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iwJs2X+t; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15A87C433F1 for ; Thu, 15 Feb 2024 22:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708037739; bh=QLeyHs3xueE6EjPGnnRWIhs2QexL6hddi0ZMopmicXI=; h=Subject:From:To:Date:In-Reply-To:References:From; b=iwJs2X+tBKLugjFBvxI6fy7U6oGx2wgKrvPnrViAO2BSQDmFoMdByko8hs168m3jW 0xncv38Fxs4AfgT50C/pzFpcaUQmbcCklXOcz01v9QbPKwJSlU8sfEj4xDp4eWfEVV 8mfjqPvewcxvNv+liF9hQ7MFGSd+Eot7X0kzJJtE5iqFMZaM9vwhv35uD7+RfS0yhL QnwDIJV2Ioa4gnh83vIZIo43XuECyF3BhAZnS2D2wmUNsLBWS/ic50T5N7yaLQ++Uo Or6a8MMo2LW6qo/bAK/eUPaTge7gh/vd+8HKnil0SsgLH7MPYggtpAigCi1s0fM3Ne KS9UoBADvW28Q== Subject: [PATCH v2 2/2] nfsd: don't take fi_lock in nfsd_break_deleg_cb() From: Chuck Lever To: linux-nfs@vger.kernel.org Date: Thu, 15 Feb 2024 17:55:38 -0500 Message-ID: <170803773812.10525.7715180641100284609.stgit@manet.1015granger.net> In-Reply-To: <170803741752.10525.14867593238471365383.stgit@manet.1015granger.net> References: <170803741752.10525.14867593238471365383.stgit@manet.1015granger.net> User-Agent: StGit/1.5 Precedence: bulk X-Mailing-List: linux-nfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit From: NeilBrown [ Upstream commit 5ea9a7c5fe4149f165f0e3b624fe08df02b6c301 ] A recent change to check_for_locks() changed it to take ->flc_lock while holding ->fi_lock. This creates a lock inversion (reported by lockdep) because there is a case where ->fi_lock is taken while holding ->flc_lock. ->flc_lock is held across ->fl_lmops callbacks, and nfsd_break_deleg_cb() is one of those and does take ->fi_lock. However it doesn't need to. Prior to v4.17-rc1~110^2~22 ("nfsd: create a separate lease for each delegation") nfsd_break_deleg_cb() would walk the ->fi_delegations list and so needed the lock. Since then it doesn't walk the list and doesn't need the lock. Two actions are performed under the lock. One is to call nfsd_break_one_deleg which calls nfsd4_run_cb(). These doesn't act on the nfs4_file at all, so don't need the lock. The other is to set ->fi_had_conflict which is in the nfs4_file. This field is only ever set here (except when initialised to false) so there is no possible problem will multiple threads racing when setting it. The field is tested twice in nfs4_set_delegation(). The first test does not hold a lock and is documented as an opportunistic optimisation, so it doesn't impose any need to hold ->fi_lock while setting ->fi_had_conflict. The second test in nfs4_set_delegation() *is* make under ->fi_lock, so removing the locking when ->fi_had_conflict is set could make a change. The change could only be interesting if ->fi_had_conflict tested as false even though nfsd_break_one_deleg() ran before ->fi_lock was unlocked. i.e. while hash_delegation_locked() was running. As hash_delegation_lock() doesn't interact in any way with nfs4_run_cb() there can be no importance to this interaction. So this patch removes the locking from nfsd_break_one_deleg() and moves the final test on ->fi_had_conflict out of the locked region to make it clear that locking isn't important to the test. It is still tested *after* vfs_setlease() has succeeded. This might be significant and as vfs_setlease() takes ->flc_lock, and nfsd_break_one_deleg() is called under ->flc_lock this "after" is a true ordering provided by a spinlock. Fixes: edcf9725150e ("nfsd: fix RELEASE_LOCKOWNER") Signed-off-by: NeilBrown Reviewed-by: Jeff Layton Signed-off-by: Chuck Lever --- fs/nfsd/nfs4state.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c index 0443fe4e29e1..b3f6dda930d8 100644 --- a/fs/nfsd/nfs4state.c +++ b/fs/nfsd/nfs4state.c @@ -4908,10 +4908,8 @@ nfsd_break_deleg_cb(struct file_lock *fl) */ fl->fl_break_time = 0; - spin_lock(&fp->fi_lock); fp->fi_had_conflict = true; nfsd_break_one_deleg(dp); - spin_unlock(&fp->fi_lock); return false; } @@ -5499,12 +5497,13 @@ nfs4_set_delegation(struct nfsd4_open *open, struct nfs4_ol_stateid *stp, if (status) goto out_unlock; + status = -EAGAIN; + if (fp->fi_had_conflict) + goto out_unlock; + spin_lock(&state_lock); spin_lock(&fp->fi_lock); - if (fp->fi_had_conflict) - status = -EAGAIN; - else - status = hash_delegation_locked(dp, fp); + status = hash_delegation_locked(dp, fp); spin_unlock(&fp->fi_lock); spin_unlock(&state_lock);