Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp87602rdb; Wed, 7 Feb 2024 22:51:10 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU9GfVYRnp2QmLR28MNM0benVnmIfo6DTDp3B2btefMBn13w2mfjeKWioUynrRWrzBKeQiztYVHG/BrVjLWESrDq4t8UorvcsamtEftRw== X-Google-Smtp-Source: AGHT+IFU0n414xWmO+TNq/OZS4af+/W0SNXO1ZicfYwnGgNEcur9XssODAdaSU6rQLIul91tAcNh X-Received: by 2002:ac8:7c81:0:b0:42b:f036:f97d with SMTP id y1-20020ac87c81000000b0042bf036f97dmr7412264qtv.55.1707375070651; Wed, 07 Feb 2024 22:51:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707375070; cv=pass; d=google.com; s=arc-20160816; b=XFR/LF/BvAFJyTJDScyoH0Tzw38XdGQC/L+SAMTei4kDrMYX6fMKhJcOjZHrtOa1po ru1ObKbB/bYz0XB/hrNtZOkVdBxnt2mj7Y609jI4wLatweQG0pu1NCd4Xg8EY1B3cx72 O3SCDt4deSObddspFHi4ZcGHzFHZsDI50p1Qx+31EpWungCAbMA2jqRq2UQvYq3ugX4q CksMDg09VQFPrZk3XFwZtchX2LBw3V2Bl9/g3IXzshbeOQXg+tQQksa7RRunC839r//M 1vE5WfV9ma/fAI+2p16U7WRPd+S4YJdJepAWCz5XBNRkd8/PBj2YkqmNhSqsyOB7CvUe i+Rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=GWY5fDcDbsvEkQvCAghdR3Yv04uoFe61BO1Pa+CxV0g=; fh=96XlRRn+ufP8k94hES2oZs1VKIhZ6zolDqN/mblY2RY=; b=pS/Zfc98qmuRbSJPOxKfvwfnDyzsfO4ZlI7CZ5lYV6vwNrqshUhsMJVUTAC62fuzHW e1+POHGOjfOByH9bCqdNH6nDD2eKeGdymf2EdZU/o96i80krry2xu7VPxyGx9ZdQbI7p KYaDxUl4ehGKXwqKZtbMfeJGHwA41O+uhe0c2TenMmQ/3887ZBiRfso9tj3s1k9BMDgN 4vZIaD4XA/SMF5TwIhYAl8uKcPRYb7kXfRT85CPm75l6iOIcNhSi18Dko8jdtFWYMyMZ nB47N4DNC1OTMejhgZBQaDy1+/MAiyPZ8GtmNDkMv3C81c9ipT1Al+edBwsTQ0IXmBIE wU2g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iBw3ANuL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCUPSMzZ6xkguTEFIJ0Fv6g1CbUQ495XZ9KJu+uCTbu4SMZyVXSnWe4H6Miy7o0TY1/T4oNMb9ckO/POag4+W7fFxu79uEEMNWhpLN8gOg== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id e19-20020ac85993000000b0042a3ee64327si2843322qte.590.2024.02.07.22.51.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 22:51:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-57537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iBw3ANuL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-57537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-57537-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 5C83F1C22A17 for ; Thu, 8 Feb 2024 06:51:10 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 17C4169302; Thu, 8 Feb 2024 06:50:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iBw3ANuL" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2AF04679E4; Thu, 8 Feb 2024 06:50:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707375058; cv=none; b=EBSUKIsQTkNTwATCOLZ8uPY2eXDwLDX+6gqVouL0T8swD8huNzN10I2704pdgR23tvzBM2KLjaAiqoEnEaGqYRns8PqXvhZlDoTd12Pcyqo1v06utVZAc0RTPmvszp0Ul6zVCg92GLlHzSP6brDVK3IgAzR/tezaTT/D54h4cIs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707375058; c=relaxed/simple; bh=Blq7rU4mZ+SoYBWemZfo+nUsAY0ljuEyn+/YGvZ2zAs=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=r67egsUBv0hRFLYrMWt8HHsBtLNRXhSfxbEDUVxpXss5fbZnGWXTeE67yFoloOiPxAJ/fw3b5XmbrHhXe+zz+Y79yIT9rFNR1+4YZ2QDPJ+9Ke5PRqU44cUCiGDNk/9hysDSQMapS/Bu34vvNwMsdH2Vf0LcTyMHUiCrnKYhdjc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iBw3ANuL; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86CF2C433A6; Thu, 8 Feb 2024 06:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707375057; bh=Blq7rU4mZ+SoYBWemZfo+nUsAY0ljuEyn+/YGvZ2zAs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=iBw3ANuLjTJlE+pfEJR8ExuAYxb5XFZ6EG8wFB0Yn1/I7H47a4muQxzRfE29+2ZiD myT4mNcogzX1c+OWIlTNy0OeLD8ztUO4hkaCxcErugQZ07AC0JSkBFG32QB/tBgsHr RQtjSsD05Z9LFnNJl+NlFE+JPgdL8u+BcUq/P0Hdv9KEBw6apAJpaHw1B61grzgH3S bPilqEplu3v/SxIbGP1BCm7qcdaplhUP/Uou+wEg19X/SgvBx99Km221bvu9EamSvU AxT6iC4x7KoI8RFla4Uho2IQSi/599k2g4zdqFJoFHahdGUPGHvutHhZiO8UFquivD UyQBlVVEW+2sw== Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d09fefabc1so16091591fa.1; Wed, 07 Feb 2024 22:50:57 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVcyEE9jWs9SuBb1PSlOyEwfykxlv/QKu/lHZFOQYfxGnXQYBp4wDpwkz1IFC3BJJiv2PgGMEHPc5j2Dyl1oxYGUF/c6p/tgpSdRwcQDULJxa/04BXhI45lys6DwFzQb4M/8pfqEQpNkc0UqaT7iofpXH3MHB1rP8AkAqxliGIXujh6UlxY X-Gm-Message-State: AOJu0YxK9l5LKW3YsZL1VC8eebvkwqvLtJEuAtGgDxIe4yVk3Z3nPzxn n/sdBEB28Ck9UYJQpwFefoBO1s5VUfYRYi+ieiiKCrFS2leRuHG7g1Hy7PxMhxAxL76BVul+XYX lxNJ+fYXO+oH92wQlLQSZJbAVCh0= X-Received: by 2002:a05:651c:1250:b0:2d0:ce72:570b with SMTP id h16-20020a05651c125000b002d0ce72570bmr1828377ljh.48.1707375055731; Wed, 07 Feb 2024 22:50:55 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240207092756.2087888-1-linan666@huaweicloud.com> In-Reply-To: <20240207092756.2087888-1-linan666@huaweicloud.com> From: Song Liu Date: Wed, 7 Feb 2024 22:50:43 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] block: fix deadlock between bd_link_disk_holder and partition scan To: linan666@huaweicloud.com Cc: axboe@kernel.dk, linux-raid@vger.kernel.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, yangerkun@huawei.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Feb 7, 2024 at 1:32=E2=80=AFAM wrote: > > From: Li Nan > > 'open_mutex' of gendisk is used to protect open/close block devices. But > in bd_link_disk_holder(), it is used to protect the creation of symlink > between holding disk and slave bdev, which introduces some issues. > > When bd_link_disk_holder() is called, the driver is usually in the proces= s > of initialization/modification and may suspend submitting io. At this > time, any io hold 'open_mutex', such as scanning partitions, can cause > deadlocks. For example, in raid: > > T1 T2 > bdev_open_by_dev > lock open_mutex [1] > ... > efi_partition > ... > md_submit_bio > md_ioctl mddev_syspend > -> suspend all io > md_add_new_disk > bind_rdev_to_array > bd_link_disk_holder > try lock open_mutex [2] > md_handle_request > -> wait mddev_resume > > T1 scan partition, T2 add a new device to raid. T1 waits for T2 to resume > mddev, but T2 waits for open_mutex held by T1. Deadlock occurs. > > Fix it by introducing a local mutex 'holder_mutex' to replace 'open_mutex= '. Is this to fix [1]? Do we need some Fixes and/or Closes tags? Could you please add steps to reproduce this issue? Thanks, Song [1] https://bugzilla.kernel.org/show_bug.cgi?id=3D218459 > > Signed-off-by: Li Nan > --- > block/holder.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/block/holder.c b/block/holder.c > index 37d18c13d958..5bfb0a674cc7 100644 > --- a/block/holder.c > +++ b/block/holder.c > @@ -8,6 +8,8 @@ struct bd_holder_disk { > int refcnt; > }; > > +static DEFINE_MUTEX(holder_mutex); > + > static struct bd_holder_disk *bd_find_holder_disk(struct block_device *b= dev, > struct gendisk *disk) > { > @@ -80,7 +82,7 @@ int bd_link_disk_holder(struct block_device *bdev, stru= ct gendisk *disk) > kobject_get(bdev->bd_holder_dir); > mutex_unlock(&bdev->bd_disk->open_mutex); > > - mutex_lock(&disk->open_mutex); > + mutex_lock(&holder_mutex); > WARN_ON_ONCE(!bdev->bd_holder); > > holder =3D bd_find_holder_disk(bdev, disk); > @@ -108,7 +110,7 @@ int bd_link_disk_holder(struct block_device *bdev, st= ruct gendisk *disk) > goto out_del_symlink; > list_add(&holder->list, &disk->slave_bdevs); > > - mutex_unlock(&disk->open_mutex); > + mutex_unlock(&holder_mutex); > return 0; > > out_del_symlink: > @@ -116,7 +118,7 @@ int bd_link_disk_holder(struct block_device *bdev, st= ruct gendisk *disk) > out_free_holder: > kfree(holder); > out_unlock: > - mutex_unlock(&disk->open_mutex); > + mutex_unlock(&holder_mutex); > if (ret) > kobject_put(bdev->bd_holder_dir); > return ret; > @@ -140,7 +142,7 @@ void bd_unlink_disk_holder(struct block_device *bdev,= struct gendisk *disk) > if (WARN_ON_ONCE(!disk->slave_dir)) > return; > > - mutex_lock(&disk->open_mutex); > + mutex_lock(&holder_mutex); > holder =3D bd_find_holder_disk(bdev, disk); > if (!WARN_ON_ONCE(holder =3D=3D NULL) && !--holder->refcnt) { > del_symlink(disk->slave_dir, bdev_kobj(bdev)); > @@ -149,6 +151,6 @@ void bd_unlink_disk_holder(struct block_device *bdev,= struct gendisk *disk) > list_del_init(&holder->list); > kfree(holder); > } > - mutex_unlock(&disk->open_mutex); > + mutex_unlock(&holder_mutex); > } > EXPORT_SYMBOL_GPL(bd_unlink_disk_holder); > -- > 2.39.2 >