From: Matthew Wilcox <willy@infradead.org>
To: Daniel Golle <daniel@makrotopia.org>
Cc: Jens Axboe <axboe@kernel.dk>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Davidlohr Bueso <dave@stgolabs.net>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Chaitanya Kulkarni <kch@nvidia.com>,
Ming Lei <ming.lei@redhat.com>,
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
Date: Thu, 10 Nov 2022 15:03:01 +0000 [thread overview]
Message-ID: <Y20SpcPNbdhcM9ps@casper.infradead.org> (raw)
In-Reply-To: <Y2xZa9z3HHtddG3t@makrotopia.org>
On Thu, Nov 10, 2022 at 01:52:43AM +0000, Daniel Golle wrote:
> 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.
OK. Then I think open coding it is the right idea, just with all
the cruft removed ;-) I looked at extracting parts of
read_part_sector() into read_part_page(), but it ended up being
a two line function that wasn't terribly useful.
WARNING: multiple messages have this Message-ID (diff)
From: Matthew Wilcox <willy@infradead.org>
To: Daniel Golle <daniel@makrotopia.org>
Cc: Jens Axboe <axboe@kernel.dk>,
Miquel Raynal <miquel.raynal@bootlin.com>,
Richard Weinberger <richard@nod.at>,
Vignesh Raghavendra <vigneshr@ti.com>,
Davidlohr Bueso <dave@stgolabs.net>,
"Martin K. Petersen" <martin.petersen@oracle.com>,
Chaitanya Kulkarni <kch@nvidia.com>,
Ming Lei <ming.lei@redhat.com>,
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
Date: Thu, 10 Nov 2022 15:03:01 +0000 [thread overview]
Message-ID: <Y20SpcPNbdhcM9ps@casper.infradead.org> (raw)
In-Reply-To: <Y2xZa9z3HHtddG3t@makrotopia.org>
On Thu, Nov 10, 2022 at 01:52:43AM +0000, Daniel Golle wrote:
> 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.
OK. Then I think open coding it is the right idea, just with all
the cruft removed ;-) I looked at extracting parts of
read_part_sector() into read_part_page(), but it ended up being
a two line function that wasn't terribly useful.
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2022-11-10 15:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 23:03 [PATCH v4 2/5] block: add partition parser for U-Boot uImage.FIT Daniel Golle
2022-11-08 23:03 ` Daniel Golle
2022-11-09 13:58 ` Matthew Wilcox
2022-11-09 13:58 ` Matthew Wilcox
2022-11-09 14:36 ` Daniel Golle
2022-11-09 14:36 ` Daniel Golle
2022-11-09 17:21 ` Matthew Wilcox
2022-11-09 17:21 ` Matthew Wilcox
2022-11-10 1:52 ` Daniel Golle
2022-11-10 1:52 ` Daniel Golle
2022-11-10 15:03 ` Matthew Wilcox [this message]
2022-11-10 15:03 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Y20SpcPNbdhcM9ps@casper.infradead.org \
--to=willy@infradead.org \
--cc=axboe@kernel.dk \
--cc=daniel@makrotopia.org \
--cc=dave@stgolabs.net \
--cc=kch@nvidia.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=martin.petersen@oracle.com \
--cc=ming.lei@redhat.com \
--cc=miquel.raynal@bootlin.com \
--cc=richard@nod.at \
--cc=vigneshr@ti.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.