Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp1938233ioo; Mon, 23 May 2022 06:42:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwddFrkoYNgrVTVt3od9kDNb/iUPnmbEuVCFhJV4zpc+SiLIyHr6N91AKITrOA08uS7i4Fe X-Received: by 2002:a63:d152:0:b0:3f6:184c:ecb9 with SMTP id c18-20020a63d152000000b003f6184cecb9mr20242877pgj.278.1653313341740; Mon, 23 May 2022 06:42:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653313341; cv=none; d=google.com; s=arc-20160816; b=JODEvlZrpEBpxlIsW9pd0ep7xeeWWCUhcJ1hLntVeB8qniUA0rZS0AZVLMxkUhmCik LG6DqMaKzUfHhly1m00RzJYo5HEi2o3rkBs7OWEMUJDWvQEjwFY77Wlxbbuy6y4Ddxco mfPzeXaxQ9ypiqbGdD1F1TIwjpVPQxP583ojYk3leA9MxKSoxWuWeQBMrua+0+KREoLp KusopBKBvrxGUorcDan+X3buh+0F82Qi7YPtKSPiHhTzFiYg2vyW5u+aZ1/mpWS/fwge zKxKIYXRKM2Ex26/Behbu8MQZoZ5DVu3RxdZx9FGIQJ1d3s2A1x06RadIS/vTHE6AGDA 6YEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:to:from :subject:message-id:dkim-signature; bh=haXHvdL8Qo3VEWCfC0+lD5aPxA4r+r7ZU2MJ/lWXtKU=; b=A1xBzdyb+ODtP5QcT2FpIiBoA2HSLTukmLzJoRWKxlvlQPK421ENTTPzaUKvEQM4Vn wNhf91jPUxPiw6ITip1QOYaPt8YBw351z1Ddq7L76l3h4TyGFMLlSAoW0JMz7AYEdqme IgAcKsomB2Q/PwoKszXvP02bcDzFsJZ3rumS0x1xhE+ieNHjva7k7uufYZcjMHFv1zCc CbyxHJwbUela9qiIC5y6McUYPNAjBTER4MlMcFPvjNji3AEbpQ6oxDWCEB5I2Qm5jBSW 07fWC0BX5GKS1rzoRjPN0BhPALnFzWmP3aAiw7qbebt9s+VdNODWGi00dE2v8tymjVrR VYrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZlwAjHwq; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id ls7-20020a17090b350700b001df47daf815si15696619pjb.141.2022.05.23.06.42.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 06:42:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZlwAjHwq; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF08AC78; Mon, 23 May 2022 06:40:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236324AbiEWNk6 (ORCPT + 99 others); Mon, 23 May 2022 09:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236350AbiEWNky (ORCPT ); Mon, 23 May 2022 09:40:54 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A25ED52E7E for ; Mon, 23 May 2022 06:40:52 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 4AAD1B80DA0 for ; Mon, 23 May 2022 13:40:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90928C385AA; Mon, 23 May 2022 13:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1653313249; bh=PZygM5XbDX+uHNlJZNeMfD3GW2GqvkJcTMLRuJsjvL4=; h=Subject:From:To:Date:In-Reply-To:References:From; b=ZlwAjHwqD2XwPmXWy9N/3okh8P5/ej1QJwq/6UPkZIoKImjHmpd9xGW720y84LSYI C0nq6F2jRNDPU4nLHy89+s21vVGIj3t0DeUkpZYgiRY2WiDOPMlxK7zfD6Gl13BYlV k0+Z+fMs1yxeiifRKlBIInkPw8SIm13P1Xa3TvvxWSkjl59b5gi5kX/WEpDW+n11In IbVV1tOKs2A3Yzv7Ww9XAPBjIKzbQKvVutCn1EJKiPf/sjeFrK1RbnbDAhlBweMj9v MK+yLbvC737HtlL4tu3685QKEDpeTtSKzb7q5aFj3VGUUL50ufGRhZxqztxb8QJ3Kx oalLmRoTiRDrg== Message-ID: Subject: Re: [PATCH RFC] NFSD: Fix possible sleep during nfsd4_release_lockowner() From: Jeff Layton To: Chuck Lever , linux-nfs@vger.kernel.org Date: Mon, 23 May 2022 09:40:48 -0400 In-Reply-To: <165323344948.2381.7808135229977810927.stgit@bazille.1015granger.net> References: <165323344948.2381.7808135229977810927.stgit@bazille.1015granger.net> Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.1 (3.44.1-1.fc36) MIME-Version: 1.0 X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org On Sun, 2022-05-22 at 11:38 -0400, Chuck Lever wrote: > nfsd4_release_lockowner() holds clp->cl_lock when it calls > check_for_locks(). However, check_for_locks() calls nfsd_file_get() > / nfsd_file_put() to access the backing inode's flc_posix list, and > nfsd_file_put() can sleep if the inode was recently removed. >=20 It might be good to add a might_sleep() to nfsd_file_put? > Let's instead rely on the stateowner's reference count to gate > whether the release is permitted. This should be a reliable > indication of locks-in-use since file lock operations and > ->lm_get_owner take appropriate references, which are released > appropriately when file locks are removed. >=20 > Reported-by: Dai Ngo > Signed-off-by: Chuck Lever > Cc: stable@vger.kernel.org > --- > fs/nfsd/nfs4state.c | 9 +++------ > 1 file changed, 3 insertions(+), 6 deletions(-) >=20 > This might be a naive approach, but let's start with it. >=20 > This passes light testing, but it's not clear how much our existing > fleet of tests exercises this area. I've locally built a couple of > pynfs tests (one is based on the one Dai posted last week) and they > pass too. >=20 > I don't believe that FREE_STATEID needs the same simplification. >=20 > diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c > index a280256cbb03..b77894e668a4 100644 > --- a/fs/nfsd/nfs4state.c > +++ b/fs/nfsd/nfs4state.c > @@ -7559,12 +7559,9 @@ nfsd4_release_lockowner(struct svc_rqst *rqstp, > =20 > /* see if there are still any locks associated with it */ > lo =3D lockowner(sop); > - list_for_each_entry(stp, &sop->so_stateids, st_perstateowner) { > - if (check_for_locks(stp->st_stid.sc_file, lo)) { > - status =3D nfserr_locks_held; > - spin_unlock(&clp->cl_lock); > - return status; > - } > + if (atomic_read(&sop->so_count) > 1) { > + spin_unlock(&clp->cl_lock); > + return nfserr_locks_held; > } > =20 > nfs4_get_stateowner(sop); >=20 >=20 lm_get_owner is called from locks_copy_conflock, so if someone else happens to be doing a LOCKT or F_GETLK call at the same time that RELEASE_LOCKOWNER gets called, then this may end up returning an error inappropriately. My guess is that that would be pretty hard to hit the timing right, but not impossible. What we may want to do is have the kernel do this check and only if it comes back >1 do the actual check for locks. That won't fix the original problem though. In other places in nfsd, we've plumbed in a dispose_list head and deferred the sleeping functions until the spinlock can be dropped. I haven't looked closely at whether that's possible here, but it may be a more reliable approach. --=20 Jeff Layton