From patchwork Tue Nov 8 23:02:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 17265 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp25959wru; Tue, 8 Nov 2022 15:09:19 -0800 (PST) X-Google-Smtp-Source: AMsMyM7RACpDImdTMn4DhljBMsN6oBMDCDXlZ1HX+hc3c5iAd8aLGuMhN2gm/F1X9TC6kai0cgxF X-Received: by 2002:a17:90b:254c:b0:20a:8a92:ea5b with SMTP id nw12-20020a17090b254c00b0020a8a92ea5bmr58981983pjb.81.1667948958843; Tue, 08 Nov 2022 15:09:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667948958; cv=none; d=google.com; s=arc-20160816; b=ngGARfWP5RYRlqZMq8b5DWJxtMgUnGJbAnYXRCLBN+5o7BEg/E5uQzXhlPVOeoFMCv 7KVVanA2gyGVJ766sKVFeaBRCC5TfTBFusO5a5gha+3/BfduwX6+rq6z25jpkG9bGtHs ejMxzo2BhJmiEGfWPWWEQgvkbZcG7jHrIvjtMKlR/GpvTLTiIkH+yt3E2lrH9IwOdTTe PfVyLAgmOzonXw/GCmeP92HiKzsBFpsmZR+p42t815pUFV+0uBKuVrejz5s6+5TUuB/f VDjP/wlXclz0s7JzS09/Er+SDk3UtqRHNzFonk9VN9yAJ9pu1Ic6602axCRqlrACnxZ3 tRjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:to:from:date; bh=QL8a0deLAuhj1IQrO+ZAK2NOnJRVmLLYuYU2Bz1xQ2g=; b=T97LHs/zP71fF8ZqDUs9r8fOVncYVCARTKe0wwhtriMRe8CECbtinJVN0u3JYKOOkP Ppv7WiRM9bCvs48T/6QqaVNH+/WUHkx79nVOzT06rL6ByaZu7FOGWsU42sHOTPgwY9T5 GJnRrcXvxnGmayhwESc/iS/UggeIEGbb8B0v/iF489rLzkGbsQcL4OmLVKWqfl0+oTMs RmDVDKRrEzy9+yOqTlXqj0wVi9//IEgW4w6G2V3CLc0cs3hLjDWAfhAh6p4sDTMPJJq7 2hG+BDcYax83+F3IensrwwwroTlVdahp1BdmUMDYsWpv+Cr8k0Oc2icZCk6ILsO5NPsG KaPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j1-20020a63e741000000b0042bc2bd5797si15527418pgk.278.2022.11.08.15.09.05; Tue, 08 Nov 2022 15:09:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbiKHXE2 (ORCPT + 99 others); Tue, 8 Nov 2022 18:04:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229498AbiKHXE1 (ORCPT ); Tue, 8 Nov 2022 18:04:27 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1C4C6314B; Tue, 8 Nov 2022 15:04:26 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1osXde-0005td-94; Wed, 09 Nov 2022 00:04:14 +0100 Date: Tue, 8 Nov 2022 23:02:49 +0000 From: Daniel Golle To: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , Matthew Wilcox , "Martin K. Petersen" , Chaitanya Kulkarni , Daniel Golle , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: [PATCH v4 1/5] block: add new flag to add partitions read-only Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_00,PDS_OTHER_BAD_TLD, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748971247628511388?= X-GMAIL-MSGID: =?utf-8?q?1748971247628511388?= Add flag ADDPART_FLAG_READONLY to allow partition parsers marking a partition to be set read-only. This is needed for the uImage.FIT partition parser added by a follow-up commit: we need to be sure the contents of uImage.FIT sub-images remain unaltered they are validated using a hash within the uImage.FIT structure which also serves as partition table. Signed-off-by: Daniel Golle --- block/blk.h | 1 + block/partitions/core.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/block/blk.h b/block/blk.h index e85703ae81dd..05ac426350b2 100644 --- a/block/blk.h +++ b/block/blk.h @@ -414,6 +414,7 @@ void blk_free_ext_minor(unsigned int minor); #define ADDPART_FLAG_NONE 0 #define ADDPART_FLAG_RAID 1 #define ADDPART_FLAG_WHOLEDISK 2 +#define ADDPART_FLAG_READONLY 4 int bdev_add_partition(struct gendisk *disk, int partno, sector_t start, sector_t length); int bdev_del_partition(struct gendisk *disk, int partno); diff --git a/block/partitions/core.c b/block/partitions/core.c index b8112f52d388..355646b0707d 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -398,6 +398,9 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, goto out_del; } + if (flags & ADDPART_FLAG_READONLY) + bdev->bd_read_only = true; + /* everything is up and running, commence */ err = xa_insert(&disk->part_tbl, partno, bdev, GFP_KERNEL); if (err)