Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95508C43381 for ; Fri, 22 Mar 2019 01:58:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6D58C218FE for ; Fri, 22 Mar 2019 01:58:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727514AbfCVB65 (ORCPT ); Thu, 21 Mar 2019 21:58:57 -0400 Received: from mx2.suse.de ([195.135.220.15]:38526 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725999AbfCVB65 (ORCPT ); Thu, 21 Mar 2019 21:58:57 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 4739DADF5; Fri, 22 Mar 2019 01:58:55 +0000 (UTC) From: NeilBrown To: "J. Bruce Fields" , Jeff Layton Date: Fri, 22 Mar 2019 12:58:47 +1100 Cc: linux-fsdevel@vger.kernel.org, asn@redhat.com Subject: Re: [PATCH] locks: ignore same lock in blocked_lock_hash In-Reply-To: <20190322004233.GA28329@fieldses.org> References: <20190321112744.7832-1-jlayton@kernel.org> <20190322004233.GA28329@fieldses.org> Message-ID: <87sgvf6560.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable On Thu, Mar 21 2019, J. Bruce Fields wrote: > On Thu, Mar 21, 2019 at 07:27:44AM -0400, Jeff Layton wrote: >> Andreas reported that he was seeing the tdbtorture test fail in >> some cases with -EDEADLCK when it wasn't before. Some debugging >> showed that deadlock detection was sometimes discovering the >> caller's lock request itself in a dependency chain. >>=20 >> If posix_locks_deadlock() fails to find a deadlock, the caller_fl >> will be passed to __locks_insert_block(), and this wakes up all >> locks that are blocked on caller_fl, clearing the fl_blocker link. >>=20 >> So if posix_locks_deadlock() finds caller_fl while searching for >> a deadlock, > > I'm feeling dense. Could you step me through the scenario in a little > more detail? Three processes: A, B, C. One byte in one file: X A gets a read lock on X. Doesn't block, so nothing goes in the hash table. B gets a read lock on X. Doesn't block. C tries to get a write lock on X. It cannot so it can block on either A or B. It chooses B. It check if this might cause a deadlock, but the hash is empty so it doesn't. It gets added to the hash. "C -> B" A tries to get a write lock on X. It cannot because B has a read lock, so it needs to block on B, or some child. C is a child and A's request conflicts with C's request, so A blocks on C. It first checks: Does A->C cause a loop in the hash-table? No. So it proceeds to block and adds "A->C" to the hash table. B drops its read lock. This wakes up the first child: C. C tries (again) to get a write lock on X. It cannot because A still holds a read lock, so it will have to block on A. First it must check if "C->A" will cause a loop in the hash-table ... Yes it will because "A->C" is already there - error! This is a false-positive because the very next thing to be done after posix_locks_deadlock() (while still holding all spinlocks), is __locks_insert_block(C->A) which calls __locks_wake_up_blocks(C) which calls __locks_delete_block() for any pending block ??->C and so will remove A->C from the hash. Maybe we could call __locks_wake_up_block() *before* calling posix_locks_deadlock(). That *might* make more sense.=20 =20=20 > > Also, how do we know this catches every such case? The only links in the hash table that are about to be removed are those that record that something is blocked by C (the lock we are trying to get). So these are the only ones that it is reasonable to special-case in posix_locks_deadlock(). > > And why aren't we unhashing blocks when we wake them up? We do - that is exactly when we unhash them. The problem is they we wake them up *after* we check for errors, rather than before. Thanks, NeilBrown > > --b. > >> it can be sure that link in the cycle is about to be >> broken and it need not treat it as the cause of a deadlock. >>=20 >> More details here: https://bugzilla.kernel.org/show_bug.cgi?id=3D202975 >>=20 >> Cc: stable@vger.kernel.org >> Fixes: 5946c4319ebb ("fs/locks: allow a lock request to block other requ= ests.") >> Reported-by: Andreas Schneider >> Signed-off-by: Neil Brown >> Signed-off-by: Jeff Layton >> --- >> fs/locks.c | 4 ++++ >> 1 file changed, 4 insertions(+) >>=20 >> diff --git a/fs/locks.c b/fs/locks.c >> index eaa1cfaf73b0..b074f6d7fd2d 100644 >> --- a/fs/locks.c >> +++ b/fs/locks.c >> @@ -1023,6 +1023,10 @@ static int posix_locks_deadlock(struct file_lock = *caller_fl, >> while ((block_fl =3D what_owner_is_waiting_for(block_fl))) { >> if (i++ > MAX_DEADLK_ITERATIONS) >> return 0; >> + >> + if (caller_fl =3D=3D block_fl) >> + return 0; >> + >> if (posix_same_owner(caller_fl, block_fl)) >> return 1; >> } >> --=20 >> 2.20.1 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEG8Yp69OQ2HB7X0l6Oeye3VZigbkFAlyUQVgACgkQOeye3VZi gblsog//Z4vuhGeYWWQ2mB07WDxZCfoUZDV0jaMyem1MgVBEsg2saqVooMI64w6K PucIGXZQaG0lLfhQHVR+2aSVrV088MIoSfUdBRywvUeLxqTqt6EwiQcGslNpY5Y9 iiEAzOzJS9LgjW47TRYk3vOmaDvO1iJ2abUh13OlH3GnUNRljAM1WeUVkw5C1MJ8 8dcK1rgQXYdN7avns3vNvXzE5ijHRCuHrjyHLY6ezlBfUn9YTjA/z32c2Uhw6Foe TJyqeFKWQioZCefPmyIgmnV41am+NSQOjnWxqUxqQFy+oZhbAIPJY0TvE4CS+ElO tJb150awSKsqVn1XlSC3SLwCCDCX0Q8X/+4CVm5yYkgyAHkWPnSQi0RpU2zX3JuQ yDOQIIbfh60/qFxyiqKbtcJNtgEBTOVeXx7Wf1TC8HqEtnWrV3dd6WnAg7tC3UnG U6uIqCLIOss8GWA0j65zk6um70Lz6/nO4zdrgA+IQeA45lmjscZRZv1Bzi6kfK94 QmPFPaBg3OCtuBeMbs+cPuQXUI0btFkEjkduIwmlcoIQl87Y6C7UxCvmDnBmIqv8 6f5+fJazBI0aYtdEy/Ka3hw8EgJd+WmG14w1ZPp6Ds0oAeexXysiMtfZ2AeZf8XU fIjl3F0cNs8efLx+kuZhpEnYH5Vmedj8PyJqxxKYQq4BkK4hQUY= =pDjN -----END PGP SIGNATURE----- --=-=-=--