Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1444751rwb; Wed, 9 Nov 2022 18:32:13 -0800 (PST) X-Google-Smtp-Source: AMsMyM6bf0jNYD9zKNGKBudsQYvgW4eOXDEgUd+W7/opn7j+tKiD7XFN8LGjBpxDWt6DpbtoxjQL X-Received: by 2002:a50:d5d5:0:b0:461:a30b:67a2 with SMTP id g21-20020a50d5d5000000b00461a30b67a2mr62577435edj.104.1668047532934; Wed, 09 Nov 2022 18:32:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668047532; cv=none; d=google.com; s=arc-20160816; b=ZSZIY1bdxJ3XW6zpz/PPCK1/YBcOtP9UaGw5YtxPBTuxzBrCMq4XBN7wu6uPRo4ONj 5P6/smOmQ2iYprR8DX8sCc3UcL0vNtPDGiAWDIkuKeJUZ/B6IYFRXFFXpvhGuFRrKKwl fQKzQSKh9Up0QauR6Au8BouWGp3dCgmp9lEV9y7E0vznB3KENIbuKjUk0oJGZQgSBkSe EVnym2/nBjRtkfeIEfo2+jeohlKuV9EGavDTUeT3N5r5z8yeClrQ4aohwpBFopVOIEd3 TS8sifZQUr3+64B3bxggAJSTc9IuTYTJ7x2guYnuhDi/QbJJaShhcbVX9eXAUe+ntoXj W36g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=5rEWhsba0a9CVwwyp+414pFIK+BCwWCaDo8t41PqWEw=; b=N+WT26rWvM2lh/o9rzNBcJUaZ1Ji3pZZrEFV2J/IdtSPqh22YgtZoopJjIjo+35KDS CY8WfZgGYQvcjUhcaFNUKTmM3YzwuSc+naeIeWSEeydyl/RcKSVzF89WqlQRgtQj3/aW cWyOezP/ZXuyh0egYZ7r5u01htNkc+Pv4PLPOBQ21aB7yz+eflAip7JxHCg8bkJrfP78 td4uSJQUz4DRaugEtYr1fa8izY0PurI1F9zN/F9cVymT3TBT1KuYFzBS+QKFXppYxnjQ 5GEf6HnnWCSkJJ97RN6mTnLx4lKScUKol4HkjXoejMiS9z8lLSiBnxgCQ8wMmgpfSkhE wYfA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss28-20020a170907c01c00b0078d4a0c77f9si13799749ejc.458.2022.11.09.18.31.49; Wed, 09 Nov 2022 18:32:12 -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 S232261AbiKJByi (ORCPT + 92 others); Wed, 9 Nov 2022 20:54:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbiKJBy3 (ORCPT ); Wed, 9 Nov 2022 20:54:29 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198A4C771; Wed, 9 Nov 2022 17:54:27 -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 1oswlW-0002Yx-Jg; Thu, 10 Nov 2022 02:54:02 +0100 Date: Thu, 10 Nov 2022 01:52:43 +0000 From: Daniel Golle To: Matthew Wilcox Cc: Jens Axboe , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Davidlohr Bueso , "Martin K. Petersen" , Chaitanya Kulkarni , Ming Lei , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, linux-efi@vger.kernel.org Subject: Re: [PATCH v4 2/5] block: add partition parser for U-Boot uImage.FIT Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 On Wed, Nov 09, 2022 at 05:21:01PM +0000, Matthew Wilcox wrote: > On Wed, Nov 09, 2022 at 02:36:11PM +0000, Daniel Golle wrote: > > On Wed, Nov 09, 2022 at 01:58:29PM +0000, Matthew Wilcox wrote: > > > ... actually, why can't you call read_part_sector() and avoid all of > > > this? > > > > I've tried that before and the problem is that read_part_sector() > > returns a pointer to one sector (typically 512 bytes) of data. > > And this pointer should not be accesses beyond sector boundaries, > > right? You'd have to call read_part_sector() again for the next > > sector. > > > > The FIT structure, however, usually exceeds the size of one sector, > > and having a continous memory area covering the structure as a whole > > is crucial for libfdt to do its job. > > > > I could, of course, use read_part_sector() to copy all sectors > > covering the FIT structure into a buffer, but that seemed strange > > given that read_part_sector() actually used read_mapping_page() > > (and now uses read_mapping_folio()) internally and then returns a > > pointer to the offset within the page/folio. So why not read it in one > > piece in first place instead of having it first split up to sectors > > by read_part_sector() just to then having to reassemble it into a > > continous buffer again. > > Are you guaranteed that it's "sufficiently" aligned on storage so > that it fits entirely within a single page? If not, you'll have > to copy it, vmap it, or fix libfdt to handle a segmented buffer. Yes, for the uImage.FIT to be usable for the partition parser it has to be page-aligned. There is a check which makes sure that this is the case: > + /* uImage.FIT should be aligned to page boundaries */ > + if (fit_start_sector % (1 << (PAGE_SHIFT - SECTOR_SHIFT))) > + return 0; In case of mtdblock or ubiblock devices, the image always starts at offset 0, so this is never a problem. In case of the image being stored in a GPT partition, one has to make sure that the start sector of the partition is page aligned, otherwise the above check will fail and the partition parser will bail out.