Thread (14 messages) 14 messages, 5 authors, 2023-11-11

Re: [PATCH 2/3] mm: Add folio_fill_tail() and use it in iomap

From: Matthew Wilcox <willy@infradead.org>
Date: 2023-11-10 17:09:34
Also in: gfs2, linux-fsdevel, linux-xfs

On Thu, Nov 09, 2023 at 10:50:45PM +0100, Andreas Gruenbacher wrote:
On Tue, Nov 7, 2023 at 10:27 PM Matthew Wilcox (Oracle)
[off-list ref] wrote:
quoted
+static inline void folio_fill_tail(struct folio *folio, size_t offset,
+               const char *from, size_t len)
+{
+       char *to = kmap_local_folio(folio, offset);
+
+       VM_BUG_ON(offset + len > folio_size(folio));
+
+       if (folio_test_highmem(folio)) {
+               size_t max = PAGE_SIZE - offset_in_page(offset);
+
+               while (len > max) {
+                       memcpy(to, from, max);
+                       kunmap_local(to);
+                       len -= max;
+                       from += max;
+                       offset += max;
+                       max = PAGE_SIZE;
+                       to = kmap_local_folio(folio, offset);
+               }
+       }
+
+       memcpy(to, from, len);
+       to = folio_zero_tail(folio, offset, to);
This needs to be:

to = folio_zero_tail(folio, offset  + len, to + len);
Oh, wow, that was stupid of me.  I only ran an xfstests against ext4,
which doesn't exercise this code, not gfs2 or erofs.  Thanks for
fixing this up.

I was wondering about adding the assertion:

	VM_BUG_ON((kaddr - offset) % PAGE_SIZE);

to catch the possible mistake of calling kmap_local_folio(folio, 0)
instead of kmap_local_folio(folio, offset).  But maybe that's
sufficiently unlikely a mistake to bother adding a runtime check for.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help