Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp238286lqe; Fri, 5 Apr 2024 21:46:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUo1Gjh8PxWIMoC7vmOkT/zE7wW3SXrIwZatI3piN6sKyfSvb81PCAjVWIIBR270mOh2nu/HIWIVe8R0Apvqj3D7Zz/AUHLes6X7mZX2g== X-Google-Smtp-Source: AGHT+IHivXMtCCnxQh5dSRLwL34XaGRZzvZMttOfCZG7PTuyCPqrjEJ5dCs11Ojd/KG88ASg32wo X-Received: by 2002:a17:906:883:b0:a47:11c1:92d7 with SMTP id n3-20020a170906088300b00a4711c192d7mr2247123eje.69.1712378818674; Fri, 05 Apr 2024 21:46:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712378818; cv=pass; d=google.com; s=arc-20160816; b=PyMQvMUVZh/aUCnjdbz49kzqLyX6EY6uuOs1fEmQ//eWZD+hIZ0QKNVNhR030EzcJU aarMj8emNUQfCaFLTS1M1vmIeVTUJkl/60TEIM1oeqAU6Irrx0e29yk+i4wMkh8MBN8Y gIU5BG1VGYK1NTBKd3kmffcIs6+xsJhjbxENeyYLuby5c7d80mFnkvnWs1aXrqGQHxWg 5kcthciKxf5hZiOHzb/ExP+I1GrcbWrP/wPguKNlTZWcHYozQWsg8jqQd68HninzM/4f Jy7e/04O1Q4Bu9j3RIl2m+HHvPbCiVK8veoQ0yaWXn3IIktgBGYU1zvsWRY0T45LQKI/ ELHw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=tIhiZai/XuhGKAO7L+OPGtFolltjq5ipvv/SRv/Vr7Q=; fh=p9KRC5vT2zpiYbGMb+ayvUbb65Folg5l3ScPXa0NcSU=; b=0tu4riXepGnBFXoTF6FEXeUcwHpnn1gfrj6sUwB09k/JIpq2xXkHk20ay/vINTbqbZ OKvhNwD5YK1802ysS9c/8saBK9daYV6D4ZMzf5TOkXGVc0D+HR7EyMmGbVbR+b7rI6VL bEXC/HRBnJDpHGLp1hsb6kqhK2CVEaPrd82CkgrABbtrFgqycdX4OJW+bOSKCCUO1coN dmHRbnGcJ63GHi6C7mA3Bb3nlDGbT7IULRXpwqwfkTbeoEPFCyIINM+6azvVWiKgdzY5 fqARse3HxwFzUQD+2TYp0wB/o77FPvupbG0qA6Jzn1RuVKHk/jgp2pzfpsRpn9ib7myn uDew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Mnf0g/2R"; 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-133803-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133803-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id bq19-20020a170906d0d300b00a518a133d75si1321345ejb.1014.2024.04.05.21.46.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 21:46:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133803-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="Mnf0g/2R"; 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-133803-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133803-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 41DEC1F2295F for ; Sat, 6 Apr 2024 04:46:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 74B371CAAC; Sat, 6 Apr 2024 04:46:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Mnf0g/2R" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.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 3C4F91FA1 for ; Sat, 6 Apr 2024 04:46:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712378809; cv=none; b=BXsGiU9vUjrXKBX00/9fJ+2a5jfCVtNU7h1NFvGjFlMe6h49F2Q8xRwiL3sFTh/u5JuiDkNqLn2Ry5V+Jzac0vahxAA1soKSoSY/djAJa1Srscow2sg/nLDqb+uyKEWh6ZkiK7BPKb076IBykgdGlEHy9HdWq88gwAaDvnos4fk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712378809; c=relaxed/simple; bh=Pa+glBIAYGUeYvj4bbkUW/0xQGcg4XhjmjmYm9pBmZA=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Ii7RS5nGHyp5pNwAnB3jpz3kWoW4RFrrwXZkO5OEtLAl569miO2lARNJ0jrY7Zc/qDiZEtmxQAqSZPI2KXGf3uVldn1who3/rzP+NnvnVg2HTcq9/Uu9HgONkwdJycuf6Hksll6f3aL7ueSTlUo1RiFUO/34sYvwj7DLU9uNqtA= 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=Mnf0g/2R; arc=none smtp.client-ip=209.85.128.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-yw1-f202.google.com with SMTP id 00721157ae682-60a4ee41269so48079757b3.0 for ; Fri, 05 Apr 2024 21:46:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712378806; x=1712983606; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=tIhiZai/XuhGKAO7L+OPGtFolltjq5ipvv/SRv/Vr7Q=; b=Mnf0g/2RLooUEyF/mevFn7IKuVAP23dGQzKJDC+4txu8zhFS7YOjqak1eA+Gm1kTj5 Mh4u1Y+HRYVdKiCCrfmLcverMZ6khm19uYL5z5isa9j6ytEAdCAsu7wgEVcTPmSBXbjP ChAjNELIEC5vN0QiQ8ctePkPe1AxtL4LeSVQEnuT3Ps7noUYLeRZHB8F3jKQxGLTkNGB iX82Zdn1AH+8gThTIZZNKI9JpsgM7RAkwaBMJAUZiA0TRyUOVwBNYt4qWT6q8Q6G5I87 tfry+R/4lC3MizL5DP+DkCBf/MSCF5dLD1S/g3vwhmdFHyaESA4opAbhoNGi1HARgNc2 SfWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712378806; x=1712983606; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=tIhiZai/XuhGKAO7L+OPGtFolltjq5ipvv/SRv/Vr7Q=; b=Qnva/1kUQjrEP87Zs8sGsp2MfETsVapIsxYvCg9SJz7oTruwUDFAIoCf2qAWhl+yXF j2tezysdjBMwMtxyi0QHS8aba1x2Sics00KFngI2enGttmfMApqCL6TJjiv0K3vJpf4a uvwyUH8n0/tL0uYv2qLCxk9GJDPePcC4pno8WdPsmDA/V3qdezgEvKMZZdp+OaXYf3K+ vol3C9Lmkag7Fo+ZLcSXpNxKi6ULSy1JJHvyUsWQv/kH63tUzQnk5RFUK5FhrZKDyvA5 2/oU8aq/IXxrpUEVwfwBZZoO83fxLUwQQ9gveLUYAid2rQoHTV1JIFAMc9xPHM4sJ3Vc N3gQ== X-Forwarded-Encrypted: i=1; AJvYcCV9Y8jTTiDrZ4It07AUoSbM7Dnhz873EaiPp8/b46obeGm5szbGzJDJ3Dxbk2oim9K6m32MLsp1BsrBn7MOPWmnudB/51CAfuZ8jz2I X-Gm-Message-State: AOJu0Yzj4M73Om4MD+syEKd9UkE+6k2Ma0Tb+K1qRh8IpFiyEx3lk2qR Iv+9EDzlLHJSuDpKmLdmbmIe27HF82zZ4tsTPBMaWYFFsEgYPBxo5rq/orC8BDEHz/nqTB54sjH rw18uKIRxbGru3p2tdKPlk9OjVw== X-Received: from srnym.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:2728]) (user=saranyamohan job=sendgmr) by 2002:a0d:e251:0:b0:615:134c:7ef3 with SMTP id l78-20020a0de251000000b00615134c7ef3mr805341ywe.9.1712378806373; Fri, 05 Apr 2024 21:46:46 -0700 (PDT) Date: Sat, 6 Apr 2024 04:46:43 +0000 In-Reply-To: <20240405065333.GB4023@lst.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240405065333.GB4023@lst.de> X-Mailer: git-send-email 2.44.0.478.gd926399ef9-goog Message-ID: <20240406044643.2475360-1-saranyamohan@google.com> Subject: [PATCH] block: Fix BLKRRPART regression From: Saranya Muruganandam To: hch@lst.de Cc: axboe@kernel.dk, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, saranyamohan@google.com, stable@vger.kernel.org, tj@kernel.org, yukuai1@huaweicloud.com 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 | 29 +++++++++++++++++++---------- block/ioctl.c | 3 ++- include/linux/blkdev.h | 2 ++ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/block/bdev.c b/block/bdev.c index 7a5f611c3d2e3..42940bced33bb 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -652,6 +652,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; @@ -670,20 +678,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); + if (test_bit(GD_NEED_PART_SCAN, &disk->state)) { + /* + * Only return scanning errors if we are called from conexts + * 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 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_part(struct block_device *part, blk_mode_t mode) { struct gendisk *disk = part->bd_disk; diff --git a/block/ioctl.c b/block/ioctl.c index 0c76137adcaaa..128f503828cee 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -562,7 +562,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 c3e8f7cf96be9..3ed5e03109c29 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -128,6 +128,8 @@ typedef unsigned int __bitwise blk_mode_t; #define BLK_OPEN_WRITE_IOCTL ((__force blk_mode_t)(1 << 4)) /* open is exclusive wrt all other BLK_OPEN_WRITE opens to the device */ #define BLK_OPEN_RESTRICT_WRITES ((__force blk_mode_t)(1 << 5)) +/* return partition scanning errors */ +#define BLK_OPEN_STRICT_SCAN ((__force blk_mode_t)(1 << 5)) struct gendisk { /* -- 2.44.0.478.gd926399ef9-goog