From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 C26FBC43381 for ; Sat, 23 Mar 2019 12:08:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9246021925 for ; Sat, 23 Mar 2019 12:08:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553342929; bh=x5GWGLsxJpkiOODUY/48DVTasBvl0aJ2yjwt8Viq/yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=D8cZ3clnldyLpHBZNvPpHYo/CGYNKqFOooxXVGCtK3tgxRcOaTpD/RgCWAo4m54m0 BjX0BWZy33Ql+DsFF8gel6DGlxZht9vyv+5VSlw0/s/SwfDwWnBC08U3hTxNFKoUd+ 81aOGfoyMnWXM6CZmDLOAMvn2e5zMesHfb4DMU6k= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727066AbfCWMIs (ORCPT ); Sat, 23 Mar 2019 08:08:48 -0400 Received: from mail.kernel.org ([198.145.29.99]:35826 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726909AbfCWMIs (ORCPT ); Sat, 23 Mar 2019 08:08:48 -0400 Received: from localhost.localdomain (unknown [99.197.221.246]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0D73021902; Sat, 23 Mar 2019 12:08:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553342927; bh=x5GWGLsxJpkiOODUY/48DVTasBvl0aJ2yjwt8Viq/yo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OStOGcj1xAuUc5KGO7PMgmHYM7jSx/M0750xigjMIQCzF+AGrBdgVRmLgTllgOh0Y l+oas6XyuXvG7v44qCDT7zwJbM7Fu2+3aOu0afCDv/F3g4iCEz+Pz2vh0aw6vtKlAo Ue+4FapocWA3+6u1IhrCHdMQSYZDpN7ZKxStQtoU= From: Jeff Layton To: linux-fsdevel@vger.kernel.org Cc: bfields@fieldses.org, neilb@suse.com, asn@redhat.com Subject: [PATCH v2] locks: ignore same lock in blocked_lock_hash Date: Sat, 23 Mar 2019 07:08:32 -0500 Message-Id: <20190323120832.28123-1-jlayton@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190322202751.GB10961@fieldses.org> References: <20190322202751.GB10961@fieldses.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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. 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. So if posix_locks_deadlock() finds caller_fl while searching for a deadlock, 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. URL: https://bugzilla.kernel.org/show_bug.cgi?id=202975 Fixes: 5946c4319ebb ("fs/locks: allow a lock request to block other requests.") Cc: stable@vger.kernel.org Reported-by: Andreas Schneider Signed-off-by: Neil Brown Signed-off-by: Jeff Layton --- fs/locks.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index eaa1cfaf73b0..a939a274dc71 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1023,6 +1023,19 @@ static int posix_locks_deadlock(struct file_lock *caller_fl, while ((block_fl = what_owner_is_waiting_for(block_fl))) { if (i++ > MAX_DEADLK_ITERATIONS) return 0; + + /* + * It's possible that we're retrying this lock request after + * another task is has blocked on it. A lock request can't + * block itself, and any locks that are blocked on it will + * also be awoken soon (and have their fl_blocker pointer + * cleared). Any dependency chain that contains the request + * itself is therefore about to be broken, so we can safely + * ignore it. + */ + if (block_fl == caller_fl) + return 0; + if (posix_same_owner(caller_fl, block_fl)) return 1; } -- 2.20.1