Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2746255pxj; Mon, 31 May 2021 09:41:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa2CTTSqn35fNBfU+6zPWLdyk+5koASix+kJnsaejEWnp6sbtf8ZmwxEQb99s+4UZOjhlu X-Received: by 2002:a05:6402:645:: with SMTP id u5mr6348121edx.293.1622479279528; Mon, 31 May 2021 09:41:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622479279; cv=none; d=google.com; s=arc-20160816; b=B+JckcLqhE6ZXA/e+nJWxh/toluwdjE7iDZ2J7rzLBSZ4dqTPO61S76kvpQ5VEtaPu iihor4uZYn3QetxsTHusQ0zZHg3q53ckFfeCDHxwpVUf6ogEoYGE//+Q8/cIipjYYdm1 9vu9I3TIJzalCaAqwXOGuaGpqeGN/NNZ2KP0zRV/iHnpXH2/9aZz72eXC3Ol6YjIwvPQ ho46asmBw73o4KKvVgCFJtLMOUJB8sCko/ytbOI9L+LMrMnauNFKhjPaPDsBp9u2+gcR +jCtpsrHeqsmmI5VX68Gu54T5cx5XcXZbo0+JFn0W+zg+P3Bzaaw3iDO35bULaiDH3Qu yleg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TQUoKuLtM5KlWgTsoC2vdMzesD8gJHkKLb0Q4NKKDpk=; b=zebsjTBmSys/2gCX2z6tbKHqAb96lj/VeViXKIRokASf8fV3uKiGR8H4RRLEOmZ2/c mDSPliaaderS8YE/49w4gh7njvFJpzKgClNiLgWSL75XPdmroWIozv8jJ/zeeTQ9zWiz V+RrvUzKkrH6P7DDYl2rqSnVSyGA4VGMAq3f1Tg9fPaRtBKpJFjNQ3RAmIBSEQrhl65G jOKSfzEibpvjwwhTwHWyN8qe/6l0GyB8zcFmCe8/Vw0wziukNePw+w0f6+c4QwxwSX/q JL0chaOxMGQpy9Z/O1ecXbnMJQX26l9bZBf83qjsvq5lbWw7rKly51nLxzmZYiX0pvh7 mIEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pQaaF2gf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t21si12325428edd.145.2021.05.31.09.40.56; Mon, 31 May 2021 09:41:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pQaaF2gf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233784AbhEaQlo (ORCPT + 99 others); Mon, 31 May 2021 12:41:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:48418 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233541AbhEaOvm (ORCPT ); Mon, 31 May 2021 10:51:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B891161CA5; Mon, 31 May 2021 13:58:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622469490; bh=FfLlHbhceFQpqIb6A/9hOSiqrfjkSpTDA/qbL078WLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pQaaF2gfsyq/kOt7pxz0ayw3nL3ckI9chrVJpY54gkKtGasLvTQC8du4HW+87IW3p uaa8GC79Aepngp+fN9uJsHQk2OVIfPosnTxRo7Wg0sfORwRLjihOjfbDwybfN6+rUv 9Tpe+mpMpYZzI9F52KlYlcDMbFHqNWdwqA+pndzU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Gulam Mohamed , Christoph Hellwig , Ming Lei , Jens Axboe , Sasha Levin Subject: [PATCH 5.12 218/296] block: fix a race between del_gendisk and BLKRRPART Date: Mon, 31 May 2021 15:14:33 +0200 Message-Id: <20210531130711.168211296@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130703.762129381@linuxfoundation.org> References: <20210531130703.762129381@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gulam Mohamed [ Upstream commit bc6a385132601c29a6da1dbf8148c0d3c9ad36dc ] When BLKRRPART is called concurrently with del_gendisk, the partitions rescan can create a stale partition that will never be be cleaned up. Fix this by checking the the disk is up before rescanning partitions while under bd_mutex. Signed-off-by: Gulam Mohamed [hch: split from a larger patch] Signed-off-by: Christoph Hellwig Reviewed-by: Ming Lei Link: https://lore.kernel.org/r/20210514131842.1600568-3-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- fs/block_dev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/block_dev.c b/fs/block_dev.c index a5a6a7930e5e..389609bc5aa3 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1244,6 +1244,9 @@ int bdev_disk_changed(struct block_device *bdev, bool invalidate) lockdep_assert_held(&bdev->bd_mutex); + if (!(disk->flags & GENHD_FL_UP)) + return -ENXIO; + rescan: ret = blk_drop_partitions(bdev); if (ret) -- 2.30.2