summaryrefslogtreecommitdiff
path: root/sys-kernel/cairn-sources/files/5.10.10/hardened-patches/0107-mm-Fix-extra_latent_entropy.patch
diff options
context:
space:
mode:
Diffstat (limited to 'sys-kernel/cairn-sources/files/5.10.10/hardened-patches/0107-mm-Fix-extra_latent_entropy.patch')
-rw-r--r--sys-kernel/cairn-sources/files/5.10.10/hardened-patches/0107-mm-Fix-extra_latent_entropy.patch103
1 files changed, 103 insertions, 0 deletions
diff --git a/sys-kernel/cairn-sources/files/5.10.10/hardened-patches/0107-mm-Fix-extra_latent_entropy.patch b/sys-kernel/cairn-sources/files/5.10.10/hardened-patches/0107-mm-Fix-extra_latent_entropy.patch
new file mode 100644
index 000000000000..d60949d64658
--- /dev/null
+++ b/sys-kernel/cairn-sources/files/5.10.10/hardened-patches/0107-mm-Fix-extra_latent_entropy.patch
@@ -0,0 +1,103 @@
+From 3f29827dd2c6423c43d0e8e73c2e13685c7e7a4b Mon Sep 17 00:00:00 2001
+From: Thibaut Sautereau <thibaut.sautereau@ssi.gouv.fr>
+Date: Tue, 7 May 2019 11:46:21 +0200
+Subject: [PATCH 107/113] mm: Fix extra_latent_entropy
+
+Commit a9cd410a3d29 ("mm/page_alloc.c: memory hotplug: free pages as
+higher order") changed `static void __init __free_pages_boot_core()`
+into `void __free_pages_core()`, causing the following section mismatch
+warning at compile time:
+
+ WARNING: vmlinux.o(.text+0x180fe4): Section mismatch in reference from the function __free_pages_core() to the variable .meminit.data:extra_latent_entropy
+ The function __free_pages_core() references the variable __meminitdata extra_latent_entropy.
+ This is often because __free_pages_core lacks a __meminitdata annotation or the annotation of extra_latent_entropy is wrong.
+
+This commit is an attempt at fixing this issue. I'm not sure it's OK as
+we are accessing pages that are still managed by the bootmem allocator.
+The prefetching part is not an issue as it only affects struct pages.
+
+Signed-off-by: Thibaut Sautereau <thibaut.sautereau@ssi.gouv.fr>
+---
+ mm/page_alloc.c | 38 ++++++++++++++++++++++----------------
+ 1 file changed, 22 insertions(+), 16 deletions(-)
+
+diff --git a/mm/page_alloc.c b/mm/page_alloc.c
+index ded9e8536285..8730ae4244b9 100644
+--- a/mm/page_alloc.c
++++ b/mm/page_alloc.c
+@@ -1539,6 +1539,25 @@ static void __free_pages_ok(struct page *page, unsigned int order,
+ local_irq_restore(flags);
+ }
+
++static void __init __gather_extra_latent_entropy(struct page *page,
++ unsigned int nr_pages)
++{
++ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
++ unsigned long hash = 0;
++ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
++ const unsigned long *data = lowmem_page_address(page);
++
++ for (index = 0; index < end; index++)
++ hash ^= hash + data[index];
++#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
++ latent_entropy ^= hash;
++ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
++#else
++ add_device_randomness((const void *)&hash, sizeof(hash));
++#endif
++ }
++}
++
+ void __free_pages_core(struct page *page, unsigned int order)
+ {
+ unsigned int nr_pages = 1 << order;
+@@ -1558,22 +1577,6 @@ void __free_pages_core(struct page *page, unsigned int order)
+ }
+ __ClearPageReserved(p);
+ set_page_count(p, 0);
+-
+- if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
+- unsigned long hash = 0;
+- size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
+- const unsigned long *data = lowmem_page_address(page);
+-
+- for (index = 0; index < end; index++)
+- hash ^= hash + data[index];
+-#ifdef CONFIG_GCC_PLUGIN_LATENT_ENTROPY
+- latent_entropy ^= hash;
+- add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
+-#else
+- add_device_randomness((const void *)&hash, sizeof(hash));
+-#endif
+- }
+-
+ atomic_long_add(nr_pages, &page_zone(page)->managed_pages);
+
+ /*
+@@ -1632,6 +1635,7 @@ void __init memblock_free_pages(struct page *page, unsigned long pfn,
+ {
+ if (early_page_uninitialised(pfn))
+ return;
++ __gather_extra_latent_entropy(page, 1 << order);
+ __free_pages_core(page, order);
+ }
+
+@@ -1723,6 +1727,7 @@ static void __init deferred_free_range(unsigned long pfn,
+ if (nr_pages == pageblock_nr_pages &&
+ (pfn & (pageblock_nr_pages - 1)) == 0) {
+ set_pageblock_migratetype(page, MIGRATE_MOVABLE);
++ __gather_extra_latent_entropy(page, 1 << pageblock_order);
+ __free_pages_core(page, pageblock_order);
+ return;
+ }
+@@ -1730,6 +1735,7 @@ static void __init deferred_free_range(unsigned long pfn,
+ for (i = 0; i < nr_pages; i++, page++, pfn++) {
+ if ((pfn & (pageblock_nr_pages - 1)) == 0)
+ set_pageblock_migratetype(page, MIGRATE_MOVABLE);
++ __gather_extra_latent_entropy(page, 1);
+ __free_pages_core(page, 0);
+ }
+ }
+--
+2.30.0
+