Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp420365lqp; Thu, 4 Apr 2024 18:43:35 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHT+8LBJ20aKeJtwaudkEaIpJlu5BGkaAM/hxFbPufb6oA2pD6npkuY6VXAK+yamzNMcGbiedpaiC5CHR6Uagp4nPkX+YVlEA93YevLg== X-Google-Smtp-Source: AGHT+IEX1Zs8HqXtdMRgvQCw30Z8fVHzW44CYHukIoYI01+a2BPMB2moePLOBR9+IlGEwWBuopiA X-Received: by 2002:a05:6870:558f:b0:22e:a25d:1c00 with SMTP id qj15-20020a056870558f00b0022ea25d1c00mr188262oac.53.1712281415008; Thu, 04 Apr 2024 18:43:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712281414; cv=pass; d=google.com; s=arc-20160816; b=PQfTixNTQftAJcwpgCSdtIr7reNEl3okJmygS5LxT4OWeCfma32IO+SeoCpVP8qNK/ 8ab/TLMQLwh41arbHIv8oM786E8pNtnjEC6IsSZgK3bnhX22N36tGPHAJbm79YJbwdyn OHRWFBiDjqbfWymQsNReSaNh4q+VPruyW6dqOc7fBkgUIysWlvOMx59cIXLXZxfX6x8A xl+VwnItaqS7L/upyY8agCZZ0x+zF9PGgXXmRyWPx1ZevYokrk5DpZOAQZ8SE2V7h3fi pFJyeKlkPhYHaD0nOJmc6WdX0qjbFj9N22yEy3AFaHrb0X7ARRQFzpGqlgLdoTlFTK8r OqeA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=3yhnAORJgGG1KHraVLDZCGL3HZq2R87i+RUHP6rWUSg=; fh=JYW+ZPUR0pI8sk/YHRgGXnzjg8/JPJqXGMJ0ukYymZI=; b=SgRG2FeG674YgCS0XLkVDM4GD4F+v6QlJUzzpNacZDxbdeb1zf1TbkBEcjc3aXWTDO 6CK5pA9w9zwfEFHLJHGTgWDo96ZEpPNE6KfMllL7qjTTtoG2Yu8dP3bLyiMOzydJitTf LdYM3Scj2jDvKp2WM41sqYx1fupmIDFNrm248WpfTLow0cW2Ahn5K9PIJisNfuc+vxaR Z/NU8UFUINppC7KYjualcINO6xUWivy4z6Av7jrZyfnClIrd6SjW0DYWitCXYefWk0Gr Axb3mqCI4YkEjlikvhBTD/BxAJl5dUsjF0HKAD5sCmquDZTqXnwS3l4yEtIBheJevMQI cmmw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CXxi5cPS; arc=pass (i=1 spf=pass spfdomain=flex--saranyamohan.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-132313-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132313-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bs68-20020a632847000000b005e83f479bbdsi452210pgb.239.2024.04.04.18.43.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 18:43:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132313-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CXxi5cPS; arc=pass (i=1 spf=pass spfdomain=flex--saranyamohan.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-132313-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132313-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9F8FD28A29A for ; Fri, 5 Apr 2024 01:43:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DD7FDF4D; Fri, 5 Apr 2024 01:43:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CXxi5cPS" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32D086FDC for ; Fri, 5 Apr 2024 01:43:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712281404; cv=none; b=TQBerRSEF4qfvZ9a44qaAf+aiNWAxHtNem2aCvaEKqHyHPWPIUw3QX1Dd9hHtScJB3hzi6QSlviN8MC5RiAu/j60U7KxGU7jndSgt4ltGwyRDnJ8MHGVnYJIF4LgJ1pRwRWdF199HTBznoPton3COa/EwiuvIm/szD6eS3kuNxA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712281404; c=relaxed/simple; bh=URaZQzuDjC1y+JWc4rSLFFtEsZXFxrIaWQtmHQtpG64=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=dGmdsPadYGTaEK3T3cxYapy5eAs81jNBAjn8j9Bf/7xlvkLnTFjjkRltz9wcZejjnaWmuA+bvmUNdGFjDQWObLCCQ2WNGmHGRR8N2fI2wpi1TMYG74naWbHsFBzgst0PS2HXnyPIGSRqhx9E/+WkaLZzVyaRfOEQzwANk5u+8t4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--saranyamohan.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=CXxi5cPS; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--saranyamohan.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dbf216080f5so2747111276.1 for ; Thu, 04 Apr 2024 18:43:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712281402; x=1712886202; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=3yhnAORJgGG1KHraVLDZCGL3HZq2R87i+RUHP6rWUSg=; b=CXxi5cPS8ba34z1a5yDAQ9tPNaoj4imfe+/kMhEUraNVjGrGp2C4Gf0GEW3qGCPNih UhWLCWubya1a9UmRS+ry0nv1EG2mQbRQfCLWpJ7mGJ2BeJW9mrMhcGh78lwWuNEn03rV JTvEJ7D9iOvhEnPRFQAybSd9W/t4LrToV+IBlF2DkQ93YB+r1Guogbg+4HHQs/ax1viV 2E/J9ywURbrYXkkHw00Q6/FGXmETxABDwHwW/dZcO/qS3ZPrwoe2ZfLlycnkF+ctRPrj 12cgs1bBqQPGaWNWIpsV04RdjszQWYkNXbAhiKJr/OtdyRhLdaHjbYkrZOmmdVSfjsGw E6lA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712281402; x=1712886202; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=3yhnAORJgGG1KHraVLDZCGL3HZq2R87i+RUHP6rWUSg=; b=AWWI70yzixYtwGhVUxEamY8tX+y+aaOSIXrHEgaCdMIcnnwP8kpOwd/lBhlhpGU/lZ Lufv+t3LhLjGlm97pJVFJeu88NreOgxDJHh2JNsVQHs/odyx0jqeht7Sq1sK+Jhoukzy cv1rQ+GiPmTWF+mIeOTFzzOJeZFFJP0XlMOWJAJcPfOfwz5dFpzftx+IJdzK7Gpymz5Z gG1IFZnXyqUmC+NcD5QHUghnEnDUvwKGPOOKl1dbSLEOezX4FnEOloJmCppHmr80B5fN JRP+rHypxWnEmziJmJ6IUyG6nPB/dNPHZruaqv8tS6n0Z1oKVKiV6Kpua+YtmlIF5qi6 rwMw== X-Forwarded-Encrypted: i=1; AJvYcCULG2q+yZBYmeFKyuWITfCNifOFCg2pXYJH9IImNgLkLdR0B0jqOB8vGbEsJWFm8/GWkfly1HYBuWMRBNtyt5UYW2Tm1jZihSNQEmPK X-Gm-Message-State: AOJu0YxU+EYvVPcNWfxvvYgkkeadrpQH+li4YgjFtgcmm0kSbbtdp52t UXOFRDg0ic3DXI0ABCN+GUFmzW2F+PynYPJas0UwdBhdgSxqXgfqYFKORD7HmJYxWiXeZl3xRDW Chd7rCO4yXqdcZ52X9G97xtgEQg== X-Received: from saranyamohan.svl.corp.google.com ([2620:15c:2a3:200:b12b:59df:64f6:cb16]) (user=saranyamohan job=sendgmr) by 2002:a05:6902:154d:b0:dda:eee6:8e52 with SMTP id r13-20020a056902154d00b00ddaeee68e52mr352605ybu.7.1712281402308; Thu, 04 Apr 2024 18:43:22 -0700 (PDT) Date: Thu, 4 Apr 2024 18:42:53 -0700 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240405014253.748627-1-saranyamohan@google.com> Subject: [PATCH] block: Fix BLKRRPART regression From: Saranya Muruganandam To: Jens Axboe , Tejun Heo , Yu Kuai , Christoph Hellwig , stable@vger.kernel.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Saranya Muruganandam Content-Type: text/plain; charset="UTF-8" The BLKRRPART ioctl used to report errors such as EIO before we changed the blkdev_reread_part() logic. Lets add a flag and capture the errors returned by bdev_disk_changed() when the flag is set. Setting this flag for the BLKRRPART path when we want the errors to be reported when rereading partitions on the disk. Link: https://lore.kernel.org/all/20240320015134.GA14267@lst.de/ Suggested-by: Christoph Hellwig Tested: Tested by simulating failure to the block device and will propose a new test to blktests. Fixes: 4601b4b130de ("block: reopen the device in blkdev_reread_part") Reported-by: Saranya Muruganandam Signed-off-by: Saranya Muruganandam Change-Id: Idf3d97390ed78061556f8468d10d6cab24ae20b1 --- block/bdev.c | 31 +++++++++++++++++++++---------- block/ioctl.c | 3 ++- include/linux/blkdev.h | 3 +++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 77fa77cd29bee..71478f8865546 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -632,6 +632,14 @@ static void blkdev_flush_mapping(struct block_device *bdev) bdev_write_inode(bdev); } +static void blkdev_put_whole(struct block_device *bdev) +{ + if (atomic_dec_and_test(&bdev->bd_openers)) + blkdev_flush_mapping(bdev); + if (bdev->bd_disk->fops->release) + bdev->bd_disk->fops->release(bdev->bd_disk); +} + static int blkdev_get_whole(struct block_device *bdev, blk_mode_t mode) { struct gendisk *disk = bdev->bd_disk; @@ -650,18 +658,21 @@ static int blkdev_get_whole(struct block_device *bdev, blk_mode_t mode) if (!atomic_read(&bdev->bd_openers)) set_init_blocksize(bdev); - if (test_bit(GD_NEED_PART_SCAN, &disk->state)) - bdev_disk_changed(disk, false); atomic_inc(&bdev->bd_openers); - return 0; -} -static void blkdev_put_whole(struct block_device *bdev) -{ - if (atomic_dec_and_test(&bdev->bd_openers)) - blkdev_flush_mapping(bdev); - if (bdev->bd_disk->fops->release) - bdev->bd_disk->fops->release(bdev->bd_disk); + if (test_bit(GD_NEED_PART_SCAN, &disk->state)) { + /* + * Only return scanning errors if we are called from contexts + * that explicitly want them, e.g. the BLKRRPART ioctl. + */ + ret = bdev_disk_changed(disk, false); + if (ret && (mode & BLK_OPEN_STRICT_SCAN)) { + blkdev_put_whole(bdev); + return ret; + } + } + + return 0; } static int blkdev_get_part(struct block_device *part, blk_mode_t mode) diff --git a/block/ioctl.c b/block/ioctl.c index aa46f3761c3ed..e8d72d9f327fd 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -557,7 +557,8 @@ static int blkdev_common_ioctl(struct block_device *bdev, blk_mode_t mode, return -EACCES; if (bdev_is_partition(bdev)) return -EINVAL; - return disk_scan_partitions(bdev->bd_disk, mode); + return disk_scan_partitions(bdev->bd_disk, + mode | BLK_OPEN_STRICT_SCAN); case BLKTRACESTART: case BLKTRACESTOP: case BLKTRACETEARDOWN: diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 01983eece8f2a..d0104dc839b0d 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -151,6 +151,9 @@ struct access_rules_head { int max_rules; }; +/* return partition scanning errors */ +#define BLK_OPEN_STRICT_SCAN ((__force blk_mode_t)(1 << 5)) + struct gendisk { /* * major/first_minor/minors should not be set by any new driver, the -- 2.44.0.478.gd926399ef9-goog