Received: by 2002:a05:6358:795:b0:dc:4c66:fc3e with SMTP id n21csp2291931rwj; Sun, 30 Oct 2022 15:02:43 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6i7lot/r32pFyoLcRMsle1DLk540PS4kh06ouIZlyu4mKbAjjANHxgofZxGWnmHkNZEWEQ X-Received: by 2002:a17:90b:3a86:b0:213:e4d5:b61e with SMTP id om6-20020a17090b3a8600b00213e4d5b61emr1587669pjb.33.1667167363626; Sun, 30 Oct 2022 15:02:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667167363; cv=none; d=google.com; s=arc-20160816; b=y8w8VDLQHj5OYJ8ndEtSVXV3/VQ1jPa8OYU90qjtACN/dyU0hjISsV6cI4Fstshhot faOtTodBY3Hds6kpBWypfT7O/+p0rEpmtQ5HdyogxoUXwX3RHx235Y1Xh27uvjrmi7c0 K84csVTq03IYnBkdSAgMtjXpf6qm08NkB7Kg09E27bm/2WNbU8v3iSgNjhdSnsi002ic XOKClVK+8Ok33cCAm/6qW4nI3eMhp6G/WYcIpVBlmQ1O5TxIZITPAkvKRYABD+k4THJI QUpa4USgNbKfC23P6M4wE1R06EusIu4B6GNIXcA7lLgr2O3vPShRhXMyyL9CMJPplNIK 5upA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:references:in-reply-to:subject :cc:to:from:mime-version:content-transfer-encoding:dkim-signature :dkim-signature; bh=yPDvJO3PV29L332LrBBfBTWW1dvNUf+YfLIX81rWwAo=; b=FPgVghxBmYY+1DZ3VW+ZlLmx0rqp2Js2FqiV+cYSvRKQzbo6rrC/uFJ8CgqZEmqjmJ Vzk3ASwWplsuvKFKkOw6j6bDhCIdVLnGlboSmJhddUD5pL11J2h3b7oJQ6+qWCAQTcgP ZR9QYyZLGkH8i5dWjD0+AgoEL3R9Nwryd91gf4QQnaK/RYdvC3D5Qnp43L2WXqDRSnIx DkPvvpC3f9uAlpig09COhJxCvX2II6lRJ1IRF3Y5Bcj2LQqa7iRT1bANDXNHo4vRl31H QyJkqtEGT3XPruPoYjAthZ6TK8YfDr4IVw1YUlq0N4C4TxDdP/PEvqSU1q2pdaQXaUzB 4Pbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="ZFmWK1/m"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=9jMhHaNg; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e9-20020a63db09000000b00459ba7ace44si6562949pgg.514.2022.10.30.15.02.23; Sun, 30 Oct 2022 15:02:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="ZFmWK1/m"; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b=9jMhHaNg; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229500AbiJ3Vpc (ORCPT + 99 others); Sun, 30 Oct 2022 17:45:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229476AbiJ3Vpb (ORCPT ); Sun, 30 Oct 2022 17:45:31 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23315A190 for ; Sun, 30 Oct 2022 14:45:31 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id CCEB320FBB; Sun, 30 Oct 2022 21:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1667166329; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yPDvJO3PV29L332LrBBfBTWW1dvNUf+YfLIX81rWwAo=; b=ZFmWK1/mDnewTv3EcMeJT6sOZt+EWbsJdHCoLvG9hXAiuBsGu4bAvAZRkei0PD8OvTj2xO Bt6e8FhDEuMvi9ALVyK/3d4Z7JcrX8svzTQ7U7rJLYCvrlOUavUdUzyFYqvtfz+bcvSXpF Vn8UibZ4Svjq8Lp4x/wr8KDdY6MnIIk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1667166329; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yPDvJO3PV29L332LrBBfBTWW1dvNUf+YfLIX81rWwAo=; b=9jMhHaNgWEEJnaZz+hVvl4R0Mf/3oYoxhYx7XbIPAAnL3H1HyjNOeW4qoOw/r7av5u0F4i o8r7ztcKLdbSHwBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A4FC813A37; Sun, 30 Oct 2022 21:45:28 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id Fz5sF3jwXmP/PQAAMHmgww (envelope-from ); Sun, 30 Oct 2022 21:45:28 +0000 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit MIME-Version: 1.0 From: "NeilBrown" To: "Chuck Lever III" Cc: "Jeff Layton" , "Linux NFS Mailing List" Subject: Re: [PATCH v3 3/4] nfsd: close race between unhashing and LRU addition In-reply-to: <08778EE0-CBDC-467B-ACA6-9D8E6719E1BB@oracle.com> References: <20221028185712.79863-1-jlayton@kernel.org>, <20221028185712.79863-4-jlayton@kernel.org>, <08778EE0-CBDC-467B-ACA6-9D8E6719E1BB@oracle.com> Date: Mon, 31 Oct 2022 08:45:09 +1100 Message-id: <166716630911.13915.14442550645061536898@noble.neil.brown.name> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 Sat, 29 Oct 2022, Chuck Lever III wrote: > > > On Oct 28, 2022, at 2:57 PM, Jeff Layton wrote: > > > > The list_lru_add and list_lru_del functions use list_empty checks to see > > whether the object is already on the LRU. That's fine in most cases, but > > we occasionally repurpose nf_lru after unhashing. It's possible for an > > LRU removal to remove it from a different list altogether if we lose a > > race. > > I've never seen that happen. lru field re-use is actually used in other > places in the kernel. Shouldn't we try to find and fix such races? > > Wasn't the idea to reduce the complexity of nfsd_file_put ? > I think the nfsd filecache is different from those "other places" because of nfsd_file_close_inode() and related code. If I understand correctly, nfsd can remove a file from the filecache while it is still in use. In this case it needs to be unhashed and removed from the lru - and then added to a dispose list - while it might still be active for some IO request. Prior to Commit 8d0d254b15cc ("nfsd: fix nfsd_file_unhash_and_dispose") unhash_and_dispose() wouldn't add to the dispose list unless the refcount was one. I'm not sure how racy this test was, but it would mean that it is unlikely for an nfsd_file to be added to the dispose list if it was still in use. After that commit it seems more likely that a nfsd_file will be added to a dispose list while it is in use. As we add/remove things to a dispose list without a lock, we need to be careful that no other thread will add the nfsd_file to an lru at the same time. refcounts will no longer provide that protection. Maybe we should restore the refcount protection, or maybe we need a bit as Jeff has added here. NeilBrown