hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/arch/s390/mm/init.c
....@@ -18,10 +18,11 @@
1818 #include <linux/mman.h>
1919 #include <linux/mm.h>
2020 #include <linux/swap.h>
21
+#include <linux/swiotlb.h>
2122 #include <linux/smp.h>
2223 #include <linux/init.h>
2324 #include <linux/pagemap.h>
24
-#include <linux/bootmem.h>
25
+#include <linux/memblock.h>
2526 #include <linux/memory.h>
2627 #include <linux/pfn.h>
2728 #include <linux/poison.h>
....@@ -29,11 +30,11 @@
2930 #include <linux/export.h>
3031 #include <linux/cma.h>
3132 #include <linux/gfp.h>
32
-#include <linux/memblock.h>
33
+#include <linux/dma-direct.h>
3334 #include <asm/processor.h>
3435 #include <linux/uaccess.h>
35
-#include <asm/pgtable.h>
3636 #include <asm/pgalloc.h>
37
+#include <asm/ptdump.h>
3738 #include <asm/dma.h>
3839 #include <asm/lowcore.h>
3940 #include <asm/tlb.h>
....@@ -42,12 +43,18 @@
4243 #include <asm/ctl_reg.h>
4344 #include <asm/sclp.h>
4445 #include <asm/set_memory.h>
46
+#include <asm/kasan.h>
47
+#include <asm/dma-mapping.h>
48
+#include <asm/uv.h>
49
+#include <linux/virtio_config.h>
4550
46
-pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(.bss..swapper_pg_dir);
51
+pgd_t swapper_pg_dir[PTRS_PER_PGD] __section(".bss..swapper_pg_dir");
4752
4853 unsigned long empty_zero_page, zero_page_mask;
4954 EXPORT_SYMBOL(empty_zero_page);
5055 EXPORT_SYMBOL(zero_page_mask);
56
+
57
+bool initmem_freed;
5158
5259 static void __init setup_zero_pages(void)
5360 {
....@@ -59,7 +66,7 @@
5966 order = 7;
6067
6168 /* Limit number of empty zero pages for small memory sizes */
62
- while (order > 2 && (totalram_pages >> 10) < (1UL << order))
69
+ while (order > 2 && (totalram_pages() >> 10) < (1UL << order))
6370 order--;
6471
6572 empty_zero_page = __get_free_pages(GFP_KERNEL | __GFP_ZERO, order);
....@@ -98,8 +105,9 @@
98105 S390_lowcore.user_asce = S390_lowcore.kernel_asce;
99106 crst_table_init((unsigned long *) init_mm.pgd, pgd_type);
100107 vmem_map_init();
108
+ kasan_copy_shadow(init_mm.pgd);
101109
102
- /* enable virtual mapping in kernel mode */
110
+ /* enable virtual mapping in kernel mode */
103111 __ctl_load(S390_lowcore.kernel_asce, 1, 1);
104112 __ctl_load(S390_lowcore.kernel_asce, 7, 7);
105113 __ctl_load(S390_lowcore.kernel_asce, 13, 13);
....@@ -107,13 +115,14 @@
107115 psw_bits(psw).dat = 1;
108116 psw_bits(psw).as = PSW_BITS_AS_HOME;
109117 __load_psw_mask(psw.mask);
118
+ kasan_free_early_identity();
110119
111
- sparse_memory_present_with_active_regions(MAX_NUMNODES);
112120 sparse_init();
121
+ zone_dma_bits = 31;
113122 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
114123 max_zone_pfns[ZONE_DMA] = PFN_DOWN(MAX_DMA_ADDRESS);
115124 max_zone_pfns[ZONE_NORMAL] = max_low_pfn;
116
- free_area_init_nodes(max_zone_pfns);
125
+ free_area_init(max_zone_pfns);
117126 }
118127
119128 void mark_rodata_ro(void)
....@@ -122,6 +131,58 @@
122131
123132 set_memory_ro((unsigned long)__start_ro_after_init, size >> PAGE_SHIFT);
124133 pr_info("Write protected read-only-after-init data: %luk\n", size >> 10);
134
+ debug_checkwx();
135
+}
136
+
137
+int set_memory_encrypted(unsigned long addr, int numpages)
138
+{
139
+ int i;
140
+
141
+ /* make specified pages unshared, (swiotlb, dma_free) */
142
+ for (i = 0; i < numpages; ++i) {
143
+ uv_remove_shared(addr);
144
+ addr += PAGE_SIZE;
145
+ }
146
+ return 0;
147
+}
148
+
149
+int set_memory_decrypted(unsigned long addr, int numpages)
150
+{
151
+ int i;
152
+ /* make specified pages shared (swiotlb, dma_alloca) */
153
+ for (i = 0; i < numpages; ++i) {
154
+ uv_set_shared(addr);
155
+ addr += PAGE_SIZE;
156
+ }
157
+ return 0;
158
+}
159
+
160
+/* are we a protected virtualization guest? */
161
+bool force_dma_unencrypted(struct device *dev)
162
+{
163
+ return is_prot_virt_guest();
164
+}
165
+
166
+#ifdef CONFIG_ARCH_HAS_RESTRICTED_VIRTIO_MEMORY_ACCESS
167
+
168
+int arch_has_restricted_virtio_memory_access(void)
169
+{
170
+ return is_prot_virt_guest();
171
+}
172
+EXPORT_SYMBOL(arch_has_restricted_virtio_memory_access);
173
+
174
+#endif
175
+
176
+/* protected virtualization */
177
+static void pv_init(void)
178
+{
179
+ if (!is_prot_virt_guest())
180
+ return;
181
+
182
+ /* make sure bounce buffers are shared */
183
+ swiotlb_force = SWIOTLB_FORCE;
184
+ swiotlb_init(1);
185
+ swiotlb_update_mem_attributes();
125186 }
126187
127188 void __init mem_init(void)
....@@ -132,11 +193,13 @@
132193 set_max_mapnr(max_low_pfn);
133194 high_memory = (void *) __va(max_low_pfn * PAGE_SIZE);
134195
196
+ pv_init();
197
+
135198 /* Setup guest page hinting */
136199 cmma_init();
137200
138201 /* this will put all low memory onto the freelists */
139
- free_all_bootmem();
202
+ memblock_free_all();
140203 setup_zero_pages(); /* Setup zeroed pages. */
141204
142205 cmma_init_nodat();
....@@ -146,19 +209,12 @@
146209
147210 void free_initmem(void)
148211 {
212
+ initmem_freed = true;
149213 __set_memory((unsigned long)_sinittext,
150214 (unsigned long)(_einittext - _sinittext) >> PAGE_SHIFT,
151215 SET_MEMORY_RW | SET_MEMORY_NX);
152216 free_initmem_default(POISON_FREE_INITMEM);
153217 }
154
-
155
-#ifdef CONFIG_BLK_DEV_INITRD
156
-void __init free_initrd_mem(unsigned long start, unsigned long end)
157
-{
158
- free_reserved_area((void *)start, (void *)end, POISON_FREE_INITMEM,
159
- "initrd");
160
-}
161
-#endif
162218
163219 unsigned long memory_block_size_bytes(void)
164220 {
....@@ -222,18 +278,24 @@
222278
223279 #endif /* CONFIG_CMA */
224280
225
-int arch_add_memory(int nid, u64 start, u64 size, struct vmem_altmap *altmap,
226
- bool want_memblock)
281
+int arch_add_memory(int nid, u64 start, u64 size,
282
+ struct mhp_params *params)
227283 {
228284 unsigned long start_pfn = PFN_DOWN(start);
229285 unsigned long size_pages = PFN_DOWN(size);
230286 int rc;
231287
288
+ if (WARN_ON_ONCE(params->altmap))
289
+ return -EINVAL;
290
+
291
+ if (WARN_ON_ONCE(params->pgprot.pgprot != PAGE_KERNEL.pgprot))
292
+ return -EINVAL;
293
+
232294 rc = vmem_add_mapping(start, size);
233295 if (rc)
234296 return rc;
235297
236
- rc = __add_pages(nid, start_pfn, size_pages, altmap, want_memblock);
298
+ rc = __add_pages(nid, start_pfn, size_pages, params);
237299 if (rc)
238300 vmem_remove_mapping(start, size);
239301 return rc;