Received: by 10.223.185.116 with SMTP id b49csp6428290wrg; Wed, 28 Feb 2018 09:14:13 -0800 (PST) X-Google-Smtp-Source: AH8x226QCkI6+YOssZD32yvtYmI5grv80xeBsvFlXRlvwxnm1FZ8mRVtn8wc7wwPaRg2Dp7jar1M X-Received: by 10.101.92.6 with SMTP id u6mr14802072pgr.440.1519838053049; Wed, 28 Feb 2018 09:14:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519838053; cv=none; d=google.com; s=arc-20160816; b=Jxbv8QFKxsy0uMx+k3CnzGsJ5fFhSnHerxKwhtoLdhCJTX19et4psL8Pjg7jnQ+YPU wrJr/iDfat9Q+ykQbJhsPDWO5WgyvxvXJl/aJMrgzjVBqBNkTzI+YztvNahqJKxSaPni o7kGhp+/CfITaX0cW8DdAQvTtgusvsSxouttCK2e7puBFrkNoLH/bhVE+lB18J4H0J2a 8OnIA5Ao2wEEZmI5ymSsWz8HxyyKeqqIciholrUnzAeH3yzbQQN6uZvhDkNj86TPqelU UMF8QDNcJWTsAO2cM/HV/yU3kHSrBrKyMNTUb2TnFq/yta6T6+81wch35LCgvKtgkTYF W5GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition :arc-authentication-results; bh=h1C1OSi6XkTTDASBtiQLm3afBJ0unJN7aiEqZZRoH2g=; b=bA+39D5bzKP68R/CjQvi+cTYDiyJe2djOdSG2GBhnQf88VYPxjXTOXJH0iJ9hnt4Ac ZppMa2YGZ2GPQm6wNfzdBQ5BNiANaB3EapifUDwzRdc7V90a66cQEeQUP1FiQ+roqyrM YBFwXrDZHaykhXjJ77DeBnZ6hovBGSlA6xwsnDFiIHpFnUF2x5NI4/moy6ND5cNXKEHr w/Sgsh+wPwAtEY+IrU8EqctMK2sWBuPNy0oUHbNbQ46gO/ps6xGjBK+mx0/1EViRdBU6 ljth/a9kkFwOlNXZPRtLu2IyyLZ6CtlkKttBfPd8ijDky8Agnc/Petz+GikNGKSJM/B4 fm7g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u16si1244948pgo.695.2018.02.28.09.13.57; Wed, 28 Feb 2018 09:14:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933474AbeB1RMf (ORCPT + 99 others); Wed, 28 Feb 2018 12:12:35 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:34288 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752872AbeB1Ptv (ORCPT ); Wed, 28 Feb 2018 10:49:51 -0500 Received: from [2a02:8011:400e:2:6f00:88c8:c921:d332] (helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1er3Yo-0006Xf-AZ; Wed, 28 Feb 2018 15:22:26 +0000 Received: from ben by deadeye with local (Exim 4.90_1) (envelope-from ) id 1er3Yk-0000H8-53; Wed, 28 Feb 2018 15:22:22 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Mike Snitzer" , "Joe Thornber" , "Dennis Yang" Date: Wed, 28 Feb 2018 15:20:18 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 214/254] dm thin metadata: THIN_MAX_CONCURRENT_LOCKS should be 6 In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.55-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Dennis Yang commit 490ae017f54e55bde382d45ea24bddfb6d1a0aaf upstream. For btree removal, there is a corner case that a single thread could takes 6 locks which is more than THIN_MAX_CONCURRENT_LOCKS(5) and leads to deadlock. A btree removal might eventually call rebalance_children()->rebalance3() to rebalance entries of three neighbor child nodes when shadow_spine has already acquired two write locks. In rebalance3(), it tries to shadow and acquire the write locks of all three child nodes. However, shadowing a child node requires acquiring a read lock of the original child node and a write lock of the new block. Although the read lock will be released after block shadowing, shadowing the third child node in rebalance3() could still take the sixth lock. (2 write locks for shadow_spine + 2 write locks for the first two child nodes's shadow + 1 write lock for the last child node's shadow + 1 read lock for the last child node) Signed-off-by: Dennis Yang Acked-by: Joe Thornber Signed-off-by: Mike Snitzer Signed-off-by: Ben Hutchings --- drivers/md/dm-thin-metadata.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/drivers/md/dm-thin-metadata.c +++ b/drivers/md/dm-thin-metadata.c @@ -81,10 +81,14 @@ #define SECTOR_TO_BLOCK_SHIFT 3 /* + * For btree insert: * 3 for btree insert + * 2 for btree lookup used within space map + * For btree remove: + * 2 for shadow spine + + * 4 for rebalance 3 child node */ -#define THIN_MAX_CONCURRENT_LOCKS 5 +#define THIN_MAX_CONCURRENT_LOCKS 6 /* This should be plenty */ #define SPACE_MAP_ROOT_SIZE 128