Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1msh1w-0004lO-2e for mharc-grub-devel@gnu.org; Thu, 02 Dec 2021 03:01:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:53854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msh1t-0004k5-I9 for grub-devel@gnu.org; Thu, 02 Dec 2021 03:01:21 -0500 Received: from de-smtp-delivery-102.mimecast.com ([194.104.109.102]:38632) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1msh1q-0003M8-P3 for grub-devel@gnu.org; Thu, 02 Dec 2021 03:01:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=mimecast20200619; t=1638432074; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tpidD7ARQ309jiDZjDXSGRfNTEroV33G6Y53+otdQGk=; b=dMfgpco13KXhO+F2K34LMdIJaUA2XbXMWa9Iw21H0HSPNG3YD9AQwkRtXthaCK23MlmFYH 4PjEm1AxsoDYfNu0dzqrXCiUvB92VbGwYqAXnO0yMXXutkSyUCOZsPLG46yAutG4JEH15S mPs/TVJEsEn8cnJrZNy5xIYx8f7P23I= Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05lp2169.outbound.protection.outlook.com [104.47.17.169]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-29-nRO4QXYXNI6FclT6gtjtCg-1; Thu, 02 Dec 2021 09:01:13 +0100 X-MC-Unique: nRO4QXYXNI6FclT6gtjtCg-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U1XdPy73ISEA4MoP4ed5U33C0z7wOWLQMQUpp0xwq2/ru0y0s1AEjuXHX+pUsGLtd+CwWfEJB33+ioaynmE5u0gL7tUCLd1+f+T70EiptjBFcu29ZbeC5CLZxp7eGzuAVy0WVBxj/r+dGk+LQO+WSWLgSTKYh8ro8tO14b+lrwENn8LilD1mZpaZZWh6FUaG6k+bj/89C/C61aWKXsoeDGrKdRALJic9KKr8SJQoTley6eL2OHLraSwVkfUBO/z2+ulHAtw7ERjV/EDAugQbCD4NFwhfrfBheTixcUCA/PHIU4ognJsO8XxXAgrMREfC46LEJZSPb6joPloaEyFawA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tpidD7ARQ309jiDZjDXSGRfNTEroV33G6Y53+otdQGk=; b=h9N3Z3LmcD7SwyAU5devWIHZ99yJvKHYfjY122EaGVBWh3uHjM1ECm1D+6TQjhhRFkGMt0q7EAlxw+7pN/sRj0PN+8Rw7uWx4o7EHbEueUPWuYVq6vk5lmzOvDj8Cz4dglEzjuCGFQAFmeZbkp/617RKipfEzVYuxgAD2CHLUWsq9cLAm3HfO7ftpNauY0xpxwf793/FTNMe4RsxPkbhmb6hnNSH/+Ly+JSr6VVkLOyPebm2LzeeAe2DRsWFLfsMkuhNV8Gn6CWzEQ9k4h6K36WCpauUT7g2BujmJBiFPKIwOj3WhXDMmQbPTDDdT3mWYnCrY0IbnqQ5QL8SfS7qfQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from DU2PR04MB9081.eurprd04.prod.outlook.com (2603:10a6:10:2f0::13) by DU2PR04MB8758.eurprd04.prod.outlook.com (2603:10a6:10:2e1::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23; Thu, 2 Dec 2021 08:01:11 +0000 Received: from DU2PR04MB9081.eurprd04.prod.outlook.com ([fe80::a0d2:ba21:3a3f:6478]) by DU2PR04MB9081.eurprd04.prod.outlook.com ([fe80::a0d2:ba21:3a3f:6478%3]) with mapi id 15.20.4755.016; Thu, 2 Dec 2021 08:01:11 +0000 Date: Thu, 2 Dec 2021 16:00:55 +0800 From: Michael Chang To: The development of GNU GRUB Subject: Re: [PATCH] Use full btrfs bootloader area Message-ID: <20211202080054.GB18312@mazu> References: <20211102081106.11484-1-mchang@suse.com> <20211201161656.x2z4ejxybackg34m@tomti.i.net-space.pl> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211201161656.x2z4ejxybackg34m@tomti.i.net-space.pl> User-Agent: Mutt/1.10.1 (2018-07-13) X-ClientProxiedBy: AS9PR06CA0244.eurprd06.prod.outlook.com (2603:10a6:20b:45f::35) To DU2PR04MB9081.eurprd04.prod.outlook.com (2603:10a6:10:2f0::13) MIME-Version: 1.0 Received: from localhost (2001:b011:30d0:3d49:6600:6aff:fe77:a7be) by AS9PR06CA0244.eurprd06.prod.outlook.com (2603:10a6:20b:45f::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22 via Frontend Transport; Thu, 2 Dec 2021 08:01:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3426331b-eef7-439b-c340-08d9b569e7b1 X-MS-TrafficTypeDiagnostic: DU2PR04MB8758: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:765; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: l+vcbrEFDV6He19ezXdvuLuUp6CHgksLf/Zqg/WEj+ggcnOCjn61Kb2UnGnPqr95SPMxHRWxFav25HOeQgfpauuXImpvS8QDe+QHb7pHBAIACCMrD/XQk1cLLkIGE5qi1CLM1bUSVpbQCbGVxHITXRoCmwhb0+DvObxC3fKI81aUoWdIZDqoz6/ITqo0KNmGFCJqkDoRedde4Ec94rBfvw+0JQNA6p0WZhfN609dMIpc3vIDrKoBTR2n+Bp3bb1i9L90G4eAczkOklzH9px3IdoaYhGgAKR5YumdAvNO501/IptOY6E0KsypsqgpoD4wxUAWMUeB04p+vRVlujizKuH9Lyqr7TrTnTS02GctGYSQI2dgNaWCfGMrYPPOuom2FT5AJmxnzOWw8AaRwQsDYLIp44rWhNa74OFSLqtBYdUlYdXUyx4RarJUDyQaNodmHeDWryFMDonjJd5OcvtSjxT0IIopsO0NlZzr02iHNxqycwJgvKFRls6xUvMho8GFNTe4+/1WqF4/0XpbIW65uqEdM6BzLkH4RpSVZQnu7UKzp53HPVQcmJnguz7g+xtsLt6bxZ57z8JdU1WHzvYdwLH/V0V+JAzNgO95X8cu0OBdpn2MPcdoWLZK/Z/RfFMJgGSsL+Ulv/P4JAsko2gAKgvTTHy7l0piRPu2DNFo4o4BFo2d0Tijc4iA0NuDxij3PZaftF41dk205Ek/fhGWu53nMQjQbP04qMoYv9aWai6x2L+I7fbZupoz9kSnsn/I6qMYFwL+MOF9NjZJ1jGp+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB9081.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(7916004)(366004)(508600001)(5660300002)(186003)(6916009)(33716001)(66556008)(38100700002)(8936002)(6486002)(8676002)(316002)(9686003)(1076003)(86362001)(33656002)(66476007)(6666004)(16799955002)(6496006)(2906002)(66946007)(966005)(83380400001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS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Rj0/f3BLSdTBapmNsLaOaadWDgHV5Z1MtmkrsZOdJi/Lqj+E?= =?us-ascii?Q?ktHBURqGg+dLcSdtxQaAWByUIQAKYBinZ1yVDRdr/1d/adN2yWRH2SP00m2k?= =?us-ascii?Q?0i5TVu+Rs/F5l4zsmLLA9HaguJfFxi9kKZ2fMNeTTcqqg+6ZX3jZ+vVisTWj?= =?us-ascii?Q?xQwFUkrovDj/JaM474cfz/PH0yK45m3QqXj05tAxPZ4H8PoWSrI8HQ6vllPU?= =?us-ascii?Q?JXn2Ur372/2o1y9AJuqIIcOB/WRsvifbDybAw0pQBJvsBrRWIJE2mFUhSO+B?= =?us-ascii?Q?41HtzcUBJ9jS2krfMN4ZHsf0fKO+yFYB5wCIng8rfvg77FtnJBV0WTiSPWzc?= =?us-ascii?Q?gDk0ZPcNHCbHqtmVzyz+ExtaxhQjYufL5Zu8mIPxcaSQYMb/HUEwNMkgMx+M?= =?us-ascii?Q?8B/irC7fIWgs9Bc3zIlNTD62rj4LotjCglkfPJTTuuyab+xYVVpxZDeOUkYb?= =?us-ascii?Q?O/LCCqB65dNN/NKV17xQe6v/NXiOg9//YxGvXNThiAKqwwuO6bIQGeuexq4S?= =?us-ascii?Q?h7adk26k1ef876+d73CcGS4DN1Jdi6oPZo+LWuQHPaoTPAExvZYwy+KZWsqh?= =?us-ascii?Q?r+TWcD/yxFKfQayw1EexRBon6X56XordsY1SKeOxeJzL1nglDdFy6aSKfvLc?= =?us-ascii?Q?EQ7kbLPJVaTsTfVjF7B+MCOG5IRAewsq854ZOcGYofyk/uZjbc5gp7gEZSju?= =?us-ascii?Q?SAJgZIerEk2HF1PoJfMGTHNbEbPp0oljWRRxrv3EBlwf7+NAJS5Zmgu2Mp70?= =?us-ascii?Q?/MMl97nn1JEfVR0rJEQB3KU=3D?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3426331b-eef7-439b-c340-08d9b569e7b1 X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB9081.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2021 08:01:11.4380 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: is33tTWU4T5HvqcNy27WlNU+0tROQIEMOamkZ0LqBTFQhqw92IOJjw92vXagxhB1 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8758 Received-SPF: pass client-ip=194.104.109.102; envelope-from=mchang@suse.com; helo=de-smtp-delivery-102.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MSGID_FROM_MTA_HEADER=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Dec 2021 08:01:21 -0000 On Wed, Dec 01, 2021 at 05:16:56PM +0100, Daniel Kiper wrote: > On Tue, Nov 02, 2021 at 04:11:06PM +0800, Michael Chang via Grub-devel wrote: > > Up to now grub can only embed to the first 64 KiB before primary > > s/grub/GRUB/ > > > superblock of btrfs, effectively limiting the size that could > > consequently pose restrictions to feature enablement like advancing zstd > > s/advancing/advanced/? > > > compression. > > > > This patch attempts to utilize full unused area reserved by btrfs for > > bootloader outlined in the document [1] where this paragraph quoted. > > > > "The first 1MiB on each device is unused with the exception of primary > > superblock that is on the offset 64KiB and spans 4KiB." > > > > Apart from that, adjacent sectors to superblock and first block group > > are not used for embedding in case of overflow and it's tracing. > > What do you mean by "it's tracing" here? Maybe can put it this way "useful in tracing the problem of overflow by logging it's access to adjacent sectors and don't overwrite it". > > > This patch has been tested to provide out of the box support to btrfs > > zstd compression with which grub has been installed to the partition. > > s/grub/GRUB/ > > > [1] https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#BOOTLOADER_SUPPORT > > > > Signed-off-by: Michael Chang > > --- > > grub-core/fs/btrfs.c | 80 +++++++++++++++++++++++++++++++++++++------- > > 1 file changed, 67 insertions(+), 13 deletions(-) > > > > diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c > > index 63203034d..dcd4635f1 100644 > > --- a/grub-core/fs/btrfs.c > > +++ b/grub-core/fs/btrfs.c > > @@ -2159,6 +2159,35 @@ grub_btrfs_label (grub_device_t device, char **label) > > } > > > > #ifdef GRUB_UTIL > > + > > +struct embed_region { > > + unsigned int offset; > > s/offset/start/ > > > + unsigned int len; > > s/len/secs/ > > > +}; > > + > > +#define KB_TO_SECTOR(x) ((x) << 1) > > I think this macro belongs to the include/grub/disk.h. Additionally, it > should be named, e.g., KiB_TO_GRUB_DISK_SECS and use GRUB_DISK_SECTOR_BITS. > > > +/* > > + * https://btrfs.wiki.kernel.org/index.php/Manpage/btrfs(5)#BOOTLOADER_SUPPORT > > + * The first 1MiB on each device is unused with the exception of primary > > + * superblock that is on the offset 64KiB and spans 4KiB. > > + */ > > + > > +static const struct { > > + struct embed_region available; > > + struct embed_region used[6]; > > +} area = { > > s/area/btrfs_head/? > > > + .available = {0, KB_TO_SECTOR(1024)}, /* The first 1MiB */ > > Missing space between KB_TO_SECTOR and "(". > > > + .used = { > > + {0, 1}, /* boot.S */ > > + {KB_TO_SECTOR(64) - 1, 1}, /* overflow guard */ > > Ditto and below... > > > + {KB_TO_SECTOR(64), KB_TO_SECTOR(4)}, /* 4KiB superblock */ > > + {KB_TO_SECTOR(68), 1}, /* overflow guard */ > > + {KB_TO_SECTOR(1024) - 1, 1}, /* overflow guard */ > > + {0, 0} /* array terminator */ > > + } > > +}; > > + > > static grub_err_t > > grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), > > unsigned int *nsectors, > > @@ -2166,25 +2195,50 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), > > grub_embed_type_t embed_type, > > grub_disk_addr_t **sectors) > > { > > - unsigned i; > > + unsigned int i, j; > > + const struct embed_region *u; > > + grub_disk_addr_t *map; > > + unsigned int n = 0; > > > > if (embed_type != GRUB_EMBED_PCBIOS) > > return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET, > > "BtrFS currently supports only PC-BIOS embedding"); > > > > - if (64 * 2 - 1 < *nsectors) > > - return grub_error (GRUB_ERR_OUT_OF_RANGE, > > - N_("your core.img is unusually large. " > > - "It won't fit in the embedding area")); > > - > > - *nsectors = 64 * 2 - 1; > > - if (*nsectors > max_nsectors) > > - *nsectors = max_nsectors; > > - *sectors = grub_calloc (*nsectors, sizeof (**sectors)); > > - if (!*sectors) > > + map = grub_calloc (area.available.len, sizeof (*map)); > > + if (!map) > > if (map == NULL) > > > return grub_errno; > > - for (i = 0; i < *nsectors; i++) > > - (*sectors)[i] = i + 1; > > + > > + for (u = area.used; u->len; ++u) > > + { > > + unsigned int end = u->offset + u->len; > > + > > + if (end > area.available.len) > > + end = area.available.len; > > + for (i = u->offset; i < end; ++i) > > + map[i] = 1; > > + } > > + > > + for (i = 0; i < area.available.len; ++i) > > + if (map[i] == 0) > > + n++; > > + > > + if (n < *nsectors) > > + { > > + grub_free (map); > > + return grub_error (GRUB_ERR_OUT_OF_RANGE, > > + N_("your core.img is unusually large. " > > + "It won't fit in the embedding area")); > > + } > > + > > + if (n > max_nsectors) > > + n = max_nsectors; > > + > > + for (i = 0, j = 0; i < area.available.len && j < n; ++i) > > + if (map[i] == 0) > > + map[j++] = area.available.offset + i; > > I am not fully sure what is happening in this loop. In general I would > be happy if you add more comments before each step in the code above. Thanks for review. I will add comment on those loops and agree to do all the fixups you suggested in next version. Thanks, Michael > > Daniel > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel