Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2672003pxj; Mon, 31 May 2021 07:56:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQLp/Es/+6xVNStmDy5+Ys0FxauuoJx6ENSbfpIvUF3Vou+tgiEXoFM59o2sqvW2Xy7QH9 X-Received: by 2002:a5d:8516:: with SMTP id q22mr17707107ion.173.1622472991150; Mon, 31 May 2021 07:56:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622472991; cv=none; d=google.com; s=arc-20160816; b=Jgnut5IuJ6Bp18F35Iks7nkrLcHluaSUad2iiZQyAjpmZevdg6r2Dls68p0sof6XAL 2JLir4ep72ZW8cF2SAGb1UpRZlyhm8mI2agAd/9iDIm7Tjj4mpl276CjPfGVMUFhb1U+ k6KRXGoGcTSusV2il0OI3DsdEgoSj1nvRySLqiC++29CZZ1laA8e9bgpt+464hyHsXgl VwmE8D7tuvBZYIwDloUcMj/RK6kjb5jc9Mu6M3MtwskONAlwzv5XXcwZ2BwQnwxBwTQb dqril/QycjeckO8du6Xrf20VAP/fw6xP23eJAaRrPXn2g2pUco9ZewWoK9ORJv14iJu2 ew+A== 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=d3Acejr9XR3wLJuL3JSijQWebwWHBiFIGsETOpSJYNo=; b=lj/WPgulXv+MXBSVKnkH3ENOA0j2soPtLm6RFxZoBucBOsLSx9TuC29tetKFOKSwtb 14XVbainuKgoh2uuLw0uzICer8kFib8Hfwir3H5CF4Iu4+eJXZqr9gdFgJk3c96Xr/a+ 0KpvUW8KL5Z0Opb/wbwN0t5W6jbHFKcQOs86K7eY7uExGqysP7OIxHkgOL8Yis7QP2Gb S746YClpJGu+sbnjvb4bZQarxrX+osTKT20PDfT6ATvctlWR+pcwVu8O3ZKxe3GF3s6Y 4hSL+Q9a5wHB4MMt65Tyr9sRv92TFqUChAhzC9KhBJv3aJWTNzg1+UhO23GmhPLL5o8E smiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="hUWeB/oa"; 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 y17si1196006iod.74.2021.05.31.07.56.17; Mon, 31 May 2021 07:56:31 -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="hUWeB/oa"; 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 S234013AbhEaO5R (ORCPT + 99 others); Mon, 31 May 2021 10:57:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:37808 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233309AbhEaOEZ (ORCPT ); Mon, 31 May 2021 10:04:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 50DBD61450; Mon, 31 May 2021 13:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1622468291; bh=IDRMAJny6+HkyjOT/E48tl0bKg98knhfTnaG8j+C9r8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hUWeB/oa/bfpD5yBrtF+gVwpjhXdHdGvkOhTaFB1aV//4Zr6HbuALNNIzm/DGumxo BoeAHh5i0w6cbpCr8/knRbMnoZxXrgBeq8mSUE0brgw0phNeIi8jqZh/UXnWAxNFc+ TVy9SIwXlirXoXQj1WpBEMR/RNHORZsvJRZQ33RA= 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.10 187/252] block: fix a race between del_gendisk and BLKRRPART Date: Mon, 31 May 2021 15:14:12 +0200 Message-Id: <20210531130704.362107639@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210531130657.971257589@linuxfoundation.org> References: <20210531130657.971257589@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 cacea6bafc22..29f020c4b2d0 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1408,6 +1408,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