From: Greg Kroah-Hartman Date: Wed, 6 Nov 2024 11:46:27 +0000 (+0100) Subject: 6.1-stable patches X-Git-Tag: v4.19.323~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=80be90984923a32c5c4f31967eedbc9a8b0300a5;p=thirdparty%2Fkernel%2Fstable-queue.git 6.1-stable patches added patches: migrate_pages_batch-fix-statistics-for-longterm-pin-retry.patch mm-avoid-gcc-complaint-about-pointer-casting.patch --- diff --git a/queue-6.1/migrate_pages_batch-fix-statistics-for-longterm-pin-retry.patch b/queue-6.1/migrate_pages_batch-fix-statistics-for-longterm-pin-retry.patch new file mode 100644 index 00000000000..f2ac330a454 --- /dev/null +++ b/queue-6.1/migrate_pages_batch-fix-statistics-for-longterm-pin-retry.patch @@ -0,0 +1,43 @@ +From 851ae6424697d1c4f085cb878c88168923ebcad1 Mon Sep 17 00:00:00 2001 +From: Huang Ying +Date: Mon, 17 Apr 2023 07:59:29 +0800 +Subject: migrate_pages_batch: fix statistics for longterm pin retry + +From: Huang Ying + +commit 851ae6424697d1c4f085cb878c88168923ebcad1 upstream. + +In commit fd4a7ac32918 ("mm: migrate: try again if THP split is failed due +to page refcnt"), if the THP splitting fails due to page reference count, +we will retry to improve migration successful rate. But the failed +splitting is counted as migration failure and migration retry, which will +cause duplicated failure counting. So, in this patch, this is fixed via +undoing the failure counting if we decide to retry. The patch is tested +via failure injection. + +Link: https://lkml.kernel.org/r/20230416235929.1040194-1-ying.huang@intel.com +Fixes: fd4a7ac32918 ("mm: migrate: try again if THP split is failed due to page refcnt") +Signed-off-by: "Huang, Ying" +Reviewed-by: Baolin Wang +Cc: Alistair Popple +Cc: David Hildenbrand +Cc: Yang Shi +Cc: Zi Yan +Signed-off-by: Andrew Morton +Signed-off-by: Greg Kroah-Hartman +--- + mm/migrate.c | 3 +++ + 1 file changed, 3 insertions(+) + +--- a/mm/migrate.c ++++ b/mm/migrate.c +@@ -1700,6 +1700,9 @@ split_folio_migration: + large_retry++; + thp_retry += is_thp; + nr_retry_pages += nr_pages; ++ /* Undo duplicated failure counting. */ ++ nr_large_failed--; ++ stats->nr_thp_failed -= is_thp; + break; + } + } diff --git a/queue-6.1/mm-avoid-gcc-complaint-about-pointer-casting.patch b/queue-6.1/mm-avoid-gcc-complaint-about-pointer-casting.patch new file mode 100644 index 00000000000..d897993fb11 --- /dev/null +++ b/queue-6.1/mm-avoid-gcc-complaint-about-pointer-casting.patch @@ -0,0 +1,91 @@ +From e77d587a2c04e82c6a0dffa4a32c874a4029385d Mon Sep 17 00:00:00 2001 +From: Linus Torvalds +Date: Sat, 4 Mar 2023 14:03:27 -0800 +Subject: mm: avoid gcc complaint about pointer casting +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Linus Torvalds + +commit e77d587a2c04e82c6a0dffa4a32c874a4029385d upstream. + +The migration code ends up temporarily stashing information of the wrong +type in unused fields of the newly allocated destination folio. That +all works fine, but gcc does complain about the pointer type mis-use: + + mm/migrate.c: In function ‘__migrate_folio_extract’: + mm/migrate.c:1050:20: note: randstruct: casting between randomized structure pointer types (ssa): ‘struct anon_vma’ and ‘struct address_space’ + + 1050 | *anon_vmap = (void *)dst->mapping; + | ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ + +and gcc is actually right to complain since it really doesn't understand +that this is a very temporary special case where this is ok. + +This could be fixed in different ways by just obfuscating the assignment +sufficiently that gcc doesn't see what is going on, but the truly +"proper C" way to do this is by explicitly using a union. + +Using unions for type conversions like this is normally hugely ugly and +syntactically nasty, but this really is one of the few cases where we +want to make it clear that we're not doing type conversion, we're really +re-using the value bit-for-bit just using another type. + +IOW, this should not become a common pattern, but in this one case using +that odd union is probably the best way to document to the compiler what +is conceptually going on here. + +[ Side note: there are valid cases where we convert pointers to other + pointer types, notably the whole "folio vs page" situation, where the + types actually have fundamental commonalities. + + The fact that the gcc note is limited to just randomized structures + means that we don't see equivalent warnings for those cases, but it + migth also mean that we miss other cases where we do play these kinds + of dodgy games, and this kind of explicit conversion might be a good + idea. ] + +I verified that at least for an allmodconfig build on x86-64, this +generates the exact same code, apart from line numbers and assembler +comment changes. + +Fixes: 64c8902ed441 ("migrate_pages: split unmap_and_move() to _unmap() and _move()") +Cc: Huang, Ying +Cc: Andrew Morton +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman +--- + mm/migrate.c | 10 ++++++++-- + 1 file changed, 8 insertions(+), 2 deletions(-) + +--- a/mm/migrate.c ++++ b/mm/migrate.c +@@ -1017,11 +1017,16 @@ out: + * destination folio. This is safe because nobody is using them + * except us. + */ ++union migration_ptr { ++ struct anon_vma *anon_vma; ++ struct address_space *mapping; ++}; + static void __migrate_folio_record(struct folio *dst, + unsigned long page_was_mapped, + struct anon_vma *anon_vma) + { +- dst->mapping = (void *)anon_vma; ++ union migration_ptr ptr = { .anon_vma = anon_vma }; ++ dst->mapping = ptr.mapping; + dst->private = (void *)page_was_mapped; + } + +@@ -1029,7 +1034,8 @@ static void __migrate_folio_extract(stru + int *page_was_mappedp, + struct anon_vma **anon_vmap) + { +- *anon_vmap = (void *)dst->mapping; ++ union migration_ptr ptr = { .mapping = dst->mapping }; ++ *anon_vmap = ptr.anon_vma; + *page_was_mappedp = (unsigned long)dst->private; + dst->mapping = NULL; + dst->private = NULL; diff --git a/queue-6.1/series b/queue-6.1/series index e504fc6c004..22e5b7e99f3 100644 --- a/queue-6.1/series +++ b/queue-6.1/series @@ -122,3 +122,5 @@ mtd-spi-nor-winbond-fix-w25q128-regression.patch drm-amd-display-add-null-checks-for-stream-and-plane-before-dereferencing.patch drm-amd-display-skip-on-writeback-when-it-s-not-applicable.patch vt-prevent-kernel-infoleak-in-con_font_get.patch +mm-avoid-gcc-complaint-about-pointer-casting.patch +migrate_pages_batch-fix-statistics-for-longterm-pin-retry.patch