Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp453997rdb; Tue, 16 Jan 2024 05:46:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IGqJca7b2GjDMiPlNyUDPFJ8yIGluLHbWMf/LrzEO9m715n0uNZXOUH7uecJ6m7aCFJWkrl X-Received: by 2002:a17:90a:e60f:b0:28e:86a3:11f9 with SMTP id j15-20020a17090ae60f00b0028e86a311f9mr315298pjy.34.1705412811134; Tue, 16 Jan 2024 05:46:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705412811; cv=none; d=google.com; s=arc-20160816; b=MIa5+foSCIaFE9va8R31GBdOPm922UVjqvGo0/BRY2B9fKvWwwAwoegnbuCjENWU2r yKSQHJNPX0MmF5xIj3iu05zdy/WHs5JevouRwBAv+je5EMZ2kzjSMquXRjHnEGmF9ZMm FSpRgWDDTn8VkE4aDzBg2XF7VxbHukEF1QmhKMEVUY+dLcZnaNMNiU0PSvAkOKQih0pK AvHPDgWoBbBiAtvvFcq/m0OdqAGfGjElGz2hXpSPBcu+c1dnoj7K/fAuFkI9TvVXzzLe SOXVEqIWHvu7Mirdnnkxj6IH5KJFxzm084BEQc7Eh0jx+Q29sndI9G3/eZuyr0sO8GSB ZnvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:user-agent:date:message-id:from :references:cc:to:subject; bh=vjkFUEOVDqVNS1erz0StBuiA+V/TURm3St++27jCW+g=; fh=fTIVz1ADz7K+Nfnwq8gDyO8LoaIP5GjEvghQN2mvtL0=; b=hdhxu91fODJ0fOxqbEUlXH5KgUvdpJkGrrJqod75lTJH6dFRGAiDiKHp8M/OLMBRAr GeDK5ZVUOXjgUIA9vkJm3aiciMC682uq+zwgRZ8hZMH12kkn8X/KNfCaGM22tmkhyLjH Bc6LUviy/g9Pe/gKcWvSGjI0BgOnytXcW6I1Pd3bafb5NWCpnsEtuapBxC1HLY4e8YBD V3+Rs8bRcZw7lA3hea20rSlhYkxslbPyiolOVSDq0FjzL1EUmDBxHFewTwkP1wJIwLVD KHcPlB/XE/A6wLElIRyvFwkGBbP5HYQzoI3NKgkeCZAQbTRk9nw6DNihCIt1pH3VRH9A jlrg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27432-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27432-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id sj3-20020a17090b2d8300b0028e43a187c9si5603853pjb.65.2024.01.16.05.46.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 05:46:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27432-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-27432-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27432-linux.lists.archive=gmail.com@vger.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C7E7D285880 for ; Tue, 16 Jan 2024 13:46:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 55D321BF25; Tue, 16 Jan 2024 13:46:30 +0000 (UTC) Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (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 5DAE51BF23; Tue, 16 Jan 2024 13:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TDqzb3cbZz4f3jJ2; Tue, 16 Jan 2024 21:46:19 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 39D281A0A00; Tue, 16 Jan 2024 21:46:23 +0800 (CST) Received: from [10.174.176.73] (unknown [10.174.176.73]) by APP1 (Coremail) with SMTP id cCh0CgBnOBGtiKZlSqsRBA--.20499S3; Tue, 16 Jan 2024 21:46:23 +0800 (CST) Subject: Re: PROBLEM: BLKPG_DEL_PARTITION with GENHD_FL_NO_PART used to return ENXIO, now returns EINVAL To: Yu Kuai , Christoph Hellwig , Allison Karlitskaya Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, Jens Axboe , "yukuai (C)" References: <210deda9-5439-244a-0ce2-af9dc8e5d7fe@huaweicloud.com> From: Yu Kuai Message-ID: <592625f7-36d7-02e0-2ee6-8211334aa0f9@huaweicloud.com> Date: Tue, 16 Jan 2024 21:46:21 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: <210deda9-5439-244a-0ce2-af9dc8e5d7fe@huaweicloud.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgBnOBGtiKZlSqsRBA--.20499S3 X-Coremail-Antispam: 1UD129KBjvJXoWxJw13X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, Yu Kuai 写道: > Hi, Christoph > > 在 2024/01/16 18:47, Christoph Hellwig 写道: >> Hi Allison, >> >> please try this minimal fix.  I need to double check if we historically >> returned ENXIO or EINVAL for adding / resizing partitions, which would >> make things more complicated.  Or maybe you already have data for that >> at hand? >> >> diff --git a/block/ioctl.c b/block/ioctl.c >> index 9c73a763ef8838..f2028e39767821 100644 >> --- a/block/ioctl.c >> +++ b/block/ioctl.c >> @@ -21,7 +21,7 @@ static int blkpg_do_ioctl(struct block_device *bdev, >>       sector_t start, length; >>       if (disk->flags & GENHD_FL_NO_PART) >> -        return -EINVAL; >> +        return -ENXIO; > > I think this might not be a proper fix, the reason if that before this > condition is added, -ENXIO is returned from bdev_del_partition(). And > there are also some other error number like -EACCES,-EFAULT following, > so this change will still make changes for user in other cases. Please ignore the patch from last email. Sorry for the noise... bdev_resize_partition() will also return -ENXIO if partition does't exist. So the right patch should be following: diff --git a/block/ioctl.c b/block/ioctl.c index 4160f4e6bd5b..ba8d44fa7e02 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -20,8 +20,6 @@ static int blkpg_do_ioctl(struct block_device *bdev, struct blkpg_partition p; long long start, length; - if (disk->flags & GENHD_FL_NO_PART) - return -EINVAL; if (!capable(CAP_SYS_ADMIN)) return -EACCES; if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) diff --git a/block/partitions/core.c b/block/partitions/core.c index f47ffcfdfcec..f14602022c5e 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -447,6 +447,11 @@ int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, goto out; } + if (disk->flags & GENHD_FL_NO_PART) { + ret = -EINVAL; + goto out; + } + if (partition_overlaps(disk, start, length, -1)) { ret = -EBUSY; goto out; Thanks, Kuai > > How about following patch? > > diff --git a/block/ioctl.c b/block/ioctl.c > index 4160f4e6bd5b..ec012cf910dc 100644 > --- a/block/ioctl.c > +++ b/block/ioctl.c > @@ -20,8 +20,6 @@ static int blkpg_do_ioctl(struct block_device *bdev, >         struct blkpg_partition p; >         long long start, length; > > -       if (disk->flags & GENHD_FL_NO_PART) > -               return -EINVAL; >         if (!capable(CAP_SYS_ADMIN)) >                 return -EACCES; >         if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) > @@ -38,6 +36,9 @@ static int blkpg_do_ioctl(struct block_device *bdev, >         start = p.start >> SECTOR_SHIFT; >         length = p.length >> SECTOR_SHIFT; > > +       if (disk->flags & GENHD_FL_NO_PART) > +               return -EINVAL; > + >         switch (op) { >         case BLKPG_ADD_PARTITION: >                 /* check if partition is aligned to blocksize */ > > Thanks, > Kuai > > >>       if (!capable(CAP_SYS_ADMIN)) >>           return -EACCES; >>       if (copy_from_user(&p, upart, sizeof(struct blkpg_partition))) >> >> . >> > > . >