* [PATCH 6.1.y 0/3] Fix patch backport review
@ 2026-03-09 5:01 Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 1/3] pagemap: add filemap_grab_folio() Johnny Hao
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Johnny Hao @ 2026-03-09 5:01 UTC (permalink / raw)
To: gregkh, stable; +Cc: linux-kernel, slava, willy, vishal.moola, Johnny Hao
This patch series is to backport the fix 736a0516a162
("hfs: fix general protection fault in hfs_find_init()")
to 6.1.y and the other 2 patches are its dependence.
Matthew Wilcox (Oracle) (1):
highmem: add kernel-doc for memcpy_*_folio()
Viacheslav Dubeyko (1):
hfs: fix general protection fault in hfs_find_init()
Vishal Moola (Oracle) (1):
pagemap: add filemap_grab_folio()
fs/hfs/bfind.c | 3 +
fs/hfs/btree.c | 57 +++++++++++---
fs/hfs/extent.c | 2 +-
fs/hfs/hfs_fs.h | 1 +
include/linux/highmem.h | 164 ++++++++++++++++++++++++++++++++++++++++
include/linux/pagemap.h | 20 +++++
6 files changed, 235 insertions(+), 12 deletions(-)
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 6.1.y 1/3] pagemap: add filemap_grab_folio()
2026-03-09 5:01 [PATCH 6.1.y 0/3] Fix patch backport review Johnny Hao
@ 2026-03-09 5:01 ` Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 2/3] highmem: add kernel-doc for memcpy_*_folio() Johnny Hao
2026-03-09 15:38 ` [PATCH 6.1.y 0/3] Fix patch backport review Matthew Wilcox
2 siblings, 0 replies; 5+ messages in thread
From: Johnny Hao @ 2026-03-09 5:01 UTC (permalink / raw)
To: gregkh, stable
Cc: linux-kernel, slava, willy, vishal.moola, Andrew Morton,
Johnny Hao
From: "Vishal Moola (Oracle)" <vishal.moola@gmail.com>
[ Upstream commit ee7a5906ff08e435ed95ec9fe7c7eed2c11015d2 ]
Patch series "Convert to filemap_get_folios_tag()", v5.
This patch series replaces find_get_pages_range_tag() with
filemap_get_folios_tag(). This also allows the removal of multiple calls
to compound_head() throughout.
It also makes a good chunk of the straightforward conversions to folios,
and takes the opportunity to introduce a function that grabs a folio from
the pagecache.
This patch (of 23):
Add function filemap_grab_folio() to grab a folio from the page cache.
This function is meant to serve as a folio replacement for
grab_cache_page, and is used to facilitate the removal of
find_get_pages_range_tag().
Link: https://lkml.kernel.org/r/20230104211448.4804-1-vishal.moola@gmail.com
Link: https://lkml.kernel.org/r/20230104211448.4804-2-vishal.moola@gmail.com
Signed-off-by: Vishal Moola (Oracle) <vishal.moola@gmail.com>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Johnny Hao <johnny_haocn@sina.com>
---
include/linux/pagemap.h | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index dfaa09901867..be0eb05dbd14 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -582,6 +582,26 @@ static inline struct folio *filemap_lock_folio(struct address_space *mapping,
return __filemap_get_folio(mapping, index, FGP_LOCK, 0);
}
+/**
+ * filemap_grab_folio - grab a folio from the page cache
+ * @mapping: The address space to search
+ * @index: The page index
+ *
+ * Looks up the page cache entry at @mapping & @index. If no folio is found,
+ * a new folio is created. The folio is locked, marked as accessed, and
+ * returned.
+ *
+ * Return: A found or created folio. NULL if no folio is found and failed to
+ * create a folio.
+ */
+static inline struct folio *filemap_grab_folio(struct address_space *mapping,
+ pgoff_t index)
+{
+ return __filemap_get_folio(mapping, index,
+ FGP_LOCK | FGP_ACCESSED | FGP_CREAT,
+ mapping_gfp_mask(mapping));
+}
+
/**
* find_get_page - find and get a page reference
* @mapping: the address_space to search
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 6.1.y 2/3] highmem: add kernel-doc for memcpy_*_folio()
2026-03-09 5:01 [PATCH 6.1.y 0/3] Fix patch backport review Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 1/3] pagemap: add filemap_grab_folio() Johnny Hao
@ 2026-03-09 5:01 ` Johnny Hao
2026-03-09 15:37 ` Matthew Wilcox
2026-03-09 15:38 ` [PATCH 6.1.y 0/3] Fix patch backport review Matthew Wilcox
2 siblings, 1 reply; 5+ messages in thread
From: Johnny Hao @ 2026-03-09 5:01 UTC (permalink / raw)
To: gregkh, stable
Cc: linux-kernel, slava, willy, vishal.moola, Andrew Morton,
Johnny Hao
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
[ Upstream commit 9af47276ed83cc346263e56243756543a2a33c9d ]
This was inadvertently skipped when adding the new functions.
Link: https://lkml.kernel.org/r/20240124181217.1761674-1-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Johnny Hao <johnny_haocn@sina.com>
---
include/linux/highmem.h | 164 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 164 insertions(+)
diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 44242268f53b..a2a0cfbc19a0 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -415,6 +415,170 @@ static inline void memzero_page(struct page *page, size_t offset, size_t len)
kunmap_local(addr);
}
+/**
+ * memcpy_from_folio - Copy a range of bytes from a folio.
+ * @to: The memory to copy to.
+ * @folio: The folio to read from.
+ * @offset: The first byte in the folio to read.
+ * @len: The number of bytes to copy.
+ */
+static inline void memcpy_from_folio(char *to, struct folio *folio,
+ size_t offset, size_t len)
+{
+ VM_BUG_ON(offset + len > folio_size(folio));
+
+ do {
+ const char *from = kmap_local_folio(folio, offset);
+ size_t chunk = len;
+
+ if (folio_test_highmem(folio) &&
+ chunk > PAGE_SIZE - offset_in_page(offset))
+ chunk = PAGE_SIZE - offset_in_page(offset);
+ memcpy(to, from, chunk);
+ kunmap_local(from);
+
+ to += chunk;
+ offset += chunk;
+ len -= chunk;
+ } while (len > 0);
+}
+
+/**
+ * memcpy_to_folio - Copy a range of bytes to a folio.
+ * @folio: The folio to write to.
+ * @offset: The first byte in the folio to store to.
+ * @from: The memory to copy from.
+ * @len: The number of bytes to copy.
+ */
+static inline void memcpy_to_folio(struct folio *folio, size_t offset,
+ const char *from, size_t len)
+{
+ VM_BUG_ON(offset + len > folio_size(folio));
+
+ do {
+ char *to = kmap_local_folio(folio, offset);
+ size_t chunk = len;
+
+ if (folio_test_highmem(folio) &&
+ chunk > PAGE_SIZE - offset_in_page(offset))
+ chunk = PAGE_SIZE - offset_in_page(offset);
+ memcpy(to, from, chunk);
+ kunmap_local(to);
+
+ from += chunk;
+ offset += chunk;
+ len -= chunk;
+ } while (len > 0);
+
+ flush_dcache_folio(folio);
+}
+
+/**
+ * folio_zero_tail - Zero the tail of a folio.
+ * @folio: The folio to zero.
+ * @offset: The byte offset in the folio to start zeroing at.
+ * @kaddr: The address the folio is currently mapped to.
+ *
+ * If you have already used kmap_local_folio() to map a folio, written
+ * some data to it and now need to zero the end of the folio (and flush
+ * the dcache), you can use this function. If you do not have the
+ * folio kmapped (eg the folio has been partially populated by DMA),
+ * use folio_zero_range() or folio_zero_segment() instead.
+ *
+ * Return: An address which can be passed to kunmap_local().
+ */
+static inline __must_check void *folio_zero_tail(struct folio *folio,
+ size_t offset, void *kaddr)
+{
+ size_t len = folio_size(folio) - offset;
+
+ if (folio_test_highmem(folio)) {
+ size_t max = PAGE_SIZE - offset_in_page(offset);
+
+ while (len > max) {
+ memset(kaddr, 0, max);
+ kunmap_local(kaddr);
+ len -= max;
+ offset += max;
+ max = PAGE_SIZE;
+ kaddr = kmap_local_folio(folio, offset);
+ }
+ }
+
+ memset(kaddr, 0, len);
+ flush_dcache_folio(folio);
+
+ return kaddr;
+}
+
+/**
+ * folio_fill_tail - Copy some data to a folio and pad with zeroes.
+ * @folio: The destination folio.
+ * @offset: The offset into @folio at which to start copying.
+ * @from: The data to copy.
+ * @len: How many bytes of data to copy.
+ *
+ * This function is most useful for filesystems which support inline data.
+ * When they want to copy data from the inode into the page cache, this
+ * function does everything for them. It supports large folios even on
+ * HIGHMEM configurations.
+ */
+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 + len, to + len);
+ kunmap_local(to);
+}
+
+/**
+ * memcpy_from_file_folio - Copy some bytes from a file folio.
+ * @to: The destination buffer.
+ * @folio: The folio to copy from.
+ * @pos: The position in the file.
+ * @len: The maximum number of bytes to copy.
+ *
+ * Copy up to @len bytes from this folio. This may be limited by PAGE_SIZE
+ * if the folio comes from HIGHMEM, and by the size of the folio.
+ *
+ * Return: The number of bytes copied from the folio.
+ */
+static inline size_t memcpy_from_file_folio(char *to, struct folio *folio,
+ loff_t pos, size_t len)
+{
+ size_t offset = offset_in_folio(folio, pos);
+ char *from = kmap_local_folio(folio, offset);
+
+ if (folio_test_highmem(folio)) {
+ offset = offset_in_page(offset);
+ len = min_t(size_t, len, PAGE_SIZE - offset);
+ } else
+ len = min(len, folio_size(folio) - offset);
+
+ memcpy(to, from, len);
+ kunmap_local(from);
+
+ return len;
+}
+
/**
* folio_zero_segments() - Zero two byte ranges in a folio.
* @folio: The folio to write to.
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 6.1.y 2/3] highmem: add kernel-doc for memcpy_*_folio()
2026-03-09 5:01 ` [PATCH 6.1.y 2/3] highmem: add kernel-doc for memcpy_*_folio() Johnny Hao
@ 2026-03-09 15:37 ` Matthew Wilcox
0 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2026-03-09 15:37 UTC (permalink / raw)
To: Johnny Hao
Cc: gregkh, stable, linux-kernel, slava, vishal.moola, Andrew Morton
On Mon, Mar 09, 2026 at 01:01:29PM +0800, Johnny Hao wrote:
> From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
>
> [ Upstream commit 9af47276ed83cc346263e56243756543a2a33c9d ]
what? This patch isn't that commit. That commit does indeed add
kernel-doc. This patch adds the functions themselves. Please be
more careful.
> This was inadvertently skipped when adding the new functions.
>
> Link: https://lkml.kernel.org/r/20240124181217.1761674-1-willy@infradead.org
> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> Signed-off-by: Johnny Hao <johnny_haocn@sina.com>
> ---
> include/linux/highmem.h | 164 ++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 164 insertions(+)
>
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index 44242268f53b..a2a0cfbc19a0 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -415,6 +415,170 @@ static inline void memzero_page(struct page *page, size_t offset, size_t len)
> kunmap_local(addr);
> }
>
> +/**
> + * memcpy_from_folio - Copy a range of bytes from a folio.
> + * @to: The memory to copy to.
> + * @folio: The folio to read from.
> + * @offset: The first byte in the folio to read.
> + * @len: The number of bytes to copy.
> + */
> +static inline void memcpy_from_folio(char *to, struct folio *folio,
> + size_t offset, size_t len)
> +{
> + VM_BUG_ON(offset + len > folio_size(folio));
> +
> + do {
> + const char *from = kmap_local_folio(folio, offset);
> + size_t chunk = len;
> +
> + if (folio_test_highmem(folio) &&
> + chunk > PAGE_SIZE - offset_in_page(offset))
> + chunk = PAGE_SIZE - offset_in_page(offset);
> + memcpy(to, from, chunk);
> + kunmap_local(from);
> +
> + to += chunk;
> + offset += chunk;
> + len -= chunk;
> + } while (len > 0);
> +}
> +
> +/**
> + * memcpy_to_folio - Copy a range of bytes to a folio.
> + * @folio: The folio to write to.
> + * @offset: The first byte in the folio to store to.
> + * @from: The memory to copy from.
> + * @len: The number of bytes to copy.
> + */
> +static inline void memcpy_to_folio(struct folio *folio, size_t offset,
> + const char *from, size_t len)
> +{
> + VM_BUG_ON(offset + len > folio_size(folio));
> +
> + do {
> + char *to = kmap_local_folio(folio, offset);
> + size_t chunk = len;
> +
> + if (folio_test_highmem(folio) &&
> + chunk > PAGE_SIZE - offset_in_page(offset))
> + chunk = PAGE_SIZE - offset_in_page(offset);
> + memcpy(to, from, chunk);
> + kunmap_local(to);
> +
> + from += chunk;
> + offset += chunk;
> + len -= chunk;
> + } while (len > 0);
> +
> + flush_dcache_folio(folio);
> +}
> +
> +/**
> + * folio_zero_tail - Zero the tail of a folio.
> + * @folio: The folio to zero.
> + * @offset: The byte offset in the folio to start zeroing at.
> + * @kaddr: The address the folio is currently mapped to.
> + *
> + * If you have already used kmap_local_folio() to map a folio, written
> + * some data to it and now need to zero the end of the folio (and flush
> + * the dcache), you can use this function. If you do not have the
> + * folio kmapped (eg the folio has been partially populated by DMA),
> + * use folio_zero_range() or folio_zero_segment() instead.
> + *
> + * Return: An address which can be passed to kunmap_local().
> + */
> +static inline __must_check void *folio_zero_tail(struct folio *folio,
> + size_t offset, void *kaddr)
> +{
> + size_t len = folio_size(folio) - offset;
> +
> + if (folio_test_highmem(folio)) {
> + size_t max = PAGE_SIZE - offset_in_page(offset);
> +
> + while (len > max) {
> + memset(kaddr, 0, max);
> + kunmap_local(kaddr);
> + len -= max;
> + offset += max;
> + max = PAGE_SIZE;
> + kaddr = kmap_local_folio(folio, offset);
> + }
> + }
> +
> + memset(kaddr, 0, len);
> + flush_dcache_folio(folio);
> +
> + return kaddr;
> +}
> +
> +/**
> + * folio_fill_tail - Copy some data to a folio and pad with zeroes.
> + * @folio: The destination folio.
> + * @offset: The offset into @folio at which to start copying.
> + * @from: The data to copy.
> + * @len: How many bytes of data to copy.
> + *
> + * This function is most useful for filesystems which support inline data.
> + * When they want to copy data from the inode into the page cache, this
> + * function does everything for them. It supports large folios even on
> + * HIGHMEM configurations.
> + */
> +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 + len, to + len);
> + kunmap_local(to);
> +}
> +
> +/**
> + * memcpy_from_file_folio - Copy some bytes from a file folio.
> + * @to: The destination buffer.
> + * @folio: The folio to copy from.
> + * @pos: The position in the file.
> + * @len: The maximum number of bytes to copy.
> + *
> + * Copy up to @len bytes from this folio. This may be limited by PAGE_SIZE
> + * if the folio comes from HIGHMEM, and by the size of the folio.
> + *
> + * Return: The number of bytes copied from the folio.
> + */
> +static inline size_t memcpy_from_file_folio(char *to, struct folio *folio,
> + loff_t pos, size_t len)
> +{
> + size_t offset = offset_in_folio(folio, pos);
> + char *from = kmap_local_folio(folio, offset);
> +
> + if (folio_test_highmem(folio)) {
> + offset = offset_in_page(offset);
> + len = min_t(size_t, len, PAGE_SIZE - offset);
> + } else
> + len = min(len, folio_size(folio) - offset);
> +
> + memcpy(to, from, len);
> + kunmap_local(from);
> +
> + return len;
> +}
> +
> /**
> * folio_zero_segments() - Zero two byte ranges in a folio.
> * @folio: The folio to write to.
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 6.1.y 0/3] Fix patch backport review
2026-03-09 5:01 [PATCH 6.1.y 0/3] Fix patch backport review Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 1/3] pagemap: add filemap_grab_folio() Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 2/3] highmem: add kernel-doc for memcpy_*_folio() Johnny Hao
@ 2026-03-09 15:38 ` Matthew Wilcox
2 siblings, 0 replies; 5+ messages in thread
From: Matthew Wilcox @ 2026-03-09 15:38 UTC (permalink / raw)
To: Johnny Hao; +Cc: gregkh, stable, linux-kernel, slava, vishal.moola
On Mon, Mar 09, 2026 at 01:01:27PM +0800, Johnny Hao wrote:
> This patch series is to backport the fix 736a0516a162
> ("hfs: fix general protection fault in hfs_find_init()")
> to 6.1.y and the other 2 patches are its dependence.
Please explain why backporting this fix is important. The bug has
been present for years and this is not a widely-used filesystem.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-09 15:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 5:01 [PATCH 6.1.y 0/3] Fix patch backport review Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 1/3] pagemap: add filemap_grab_folio() Johnny Hao
2026-03-09 5:01 ` [PATCH 6.1.y 2/3] highmem: add kernel-doc for memcpy_*_folio() Johnny Hao
2026-03-09 15:37 ` Matthew Wilcox
2026-03-09 15:38 ` [PATCH 6.1.y 0/3] Fix patch backport review Matthew Wilcox
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox