2 * Page Deallocation Table (PDT) support
4 * The Page Deallocation Table (PDT) is maintained by firmware and holds a
5 * list of memory addresses in which memory errors were detected.
6 * The list contains both single-bit (correctable) and double-bit
7 * (uncorrectable) errors.
11 * possible future enhancements:
12 * - add userspace interface via procfs or sysfs to clear PDT
15 #include <linux/memblock.h>
16 #include <linux/seq_file.h>
17 #include <linux/kthread.h>
18 #include <linux/initrd.h>
21 #include <asm/pdcpat.h>
22 #include <asm/sections.h>
23 #include <asm/pgtable.h>
25 enum pdt_access_type {
32 static enum pdt_access_type pdt_type;
34 /* PDT poll interval: 1 minute if errors, 5 minutes if everything OK. */
35 #define PDT_POLL_INTERVAL_DEFAULT (5*60*HZ)
36 #define PDT_POLL_INTERVAL_SHORT (1*60*HZ)
37 static unsigned long pdt_poll_interval = PDT_POLL_INTERVAL_DEFAULT;
39 /* global PDT status information */
40 static struct pdc_mem_retinfo pdt_status;
42 #define MAX_PDT_TABLE_SIZE PAGE_SIZE
43 #define MAX_PDT_ENTRIES (MAX_PDT_TABLE_SIZE / sizeof(unsigned long))
44 static unsigned long pdt_entry[MAX_PDT_ENTRIES] __page_aligned_bss;
47 * Constants for the pdt_entry format:
48 * A pdt_entry holds the physical address in bits 0-57, bits 58-61 are
49 * reserved, bit 62 is the perm bit and bit 63 is the error_type bit.
50 * The perm bit indicates whether the error have been verified as a permanent
51 * error (value of 1) or has not been verified, and may be transient (value
52 * of 0). The error_type bit indicates whether the error is a single bit error
53 * (value of 1) or a multiple bit error.
54 * On non-PAT machines phys_addr is encoded in bits 0-59 and error_type in bit
55 * 63. Those machines don't provide the perm bit.
58 #define PDT_ADDR_PHYS_MASK (pdt_type != PDT_PDC ? ~0x3f : ~0x0f)
59 #define PDT_ADDR_PERM_ERR (pdt_type != PDT_PDC ? 2UL : 0UL)
60 #define PDT_ADDR_SINGLE_ERR 1UL
62 /* report PDT entries via /proc/meminfo */
63 void arch_report_meminfo(struct seq_file *m)
65 if (pdt_type == PDT_NONE)
68 seq_printf(m, "PDT_max_entries: %7lu\n",
70 seq_printf(m, "PDT_cur_entries: %7lu\n",
71 pdt_status.pdt_entries);
74 static int get_info_pat_new(void)
76 struct pdc_pat_mem_retinfo pat_rinfo;
79 /* newer PAT machines like C8000 report info for all cells */
81 ret = pdc_pat_mem_pdt_info(&pat_rinfo);
85 pdt_status.pdt_size = pat_rinfo.max_pdt_entries;
86 pdt_status.pdt_entries = pat_rinfo.current_pdt_entries;
87 pdt_status.pdt_status = 0;
88 pdt_status.first_dbe_loc = pat_rinfo.first_dbe_loc;
89 pdt_status.good_mem = pat_rinfo.good_mem;
94 static int get_info_pat_cell(void)
96 struct pdc_pat_mem_cell_pdt_retinfo cell_rinfo;
99 /* older PAT machines like rp5470 report cell info only */
101 ret = pdc_pat_mem_pdt_cell_info(&cell_rinfo, parisc_cell_num);
105 pdt_status.pdt_size = cell_rinfo.max_pdt_entries;
106 pdt_status.pdt_entries = cell_rinfo.current_pdt_entries;
107 pdt_status.pdt_status = 0;
108 pdt_status.first_dbe_loc = cell_rinfo.first_dbe_loc;
109 pdt_status.good_mem = cell_rinfo.good_mem;
114 static void report_mem_err(unsigned long pde)
116 struct pdc_pat_mem_phys_mem_location loc;
120 addr = pde & PDT_ADDR_PHYS_MASK;
122 /* show DIMM slot description on PAT machines */
124 pdc_pat_mem_get_dimm_phys_location(&loc, addr);
125 sprintf(dimm_txt, "DIMM slot %02x, ", loc.dimm_slot);
129 pr_warn("PDT: BAD MEMORY at 0x%08lx, %s%s%s-bit error.\n",
131 pde & PDT_ADDR_PERM_ERR ? "permanent ":"",
132 pde & PDT_ADDR_SINGLE_ERR ? "single":"multi");
139 * Initialize kernel PDT structures, read initial PDT table from firmware,
140 * report all current PDT entries and mark bad memory with memblock_reserve()
141 * to avoid that the kernel will use broken memory areas.
144 void __init pdc_pdt_init(void)
147 unsigned long entries;
148 struct pdc_mem_read_pdt pdt_read_ret;
150 pdt_type = PDT_PAT_NEW;
151 ret = get_info_pat_new();
154 pdt_type = PDT_PAT_CELL;
155 ret = get_info_pat_cell();
160 /* non-PAT machines provide the standard PDC call */
161 ret = pdc_mem_pdt_info(&pdt_status);
166 pr_info("PDT: Firmware does not provide any page deallocation"
171 entries = pdt_status.pdt_entries;
172 if (WARN_ON(entries > MAX_PDT_ENTRIES))
173 entries = pdt_status.pdt_entries = MAX_PDT_ENTRIES;
175 pr_info("PDT: type %s, size %lu, entries %lu, status %lu, dbe_loc 0x%lx,"
176 " good_mem %lu MB\n",
177 pdt_type == PDT_PDC ? __stringify(PDT_PDC) :
178 pdt_type == PDT_PAT_CELL ? __stringify(PDT_PAT_CELL)
179 : __stringify(PDT_PAT_NEW),
180 pdt_status.pdt_size, pdt_status.pdt_entries,
181 pdt_status.pdt_status, pdt_status.first_dbe_loc,
182 pdt_status.good_mem / 1024 / 1024);
185 pr_info("PDT: Firmware reports all memory OK.\n");
189 if (pdt_status.first_dbe_loc &&
190 pdt_status.first_dbe_loc <= __pa((unsigned long)&_end))
191 pr_crit("CRITICAL: Bad memory inside kernel image memory area!\n");
193 pr_warn("PDT: Firmware reports %lu entries of faulty memory:\n",
196 if (pdt_type == PDT_PDC)
197 ret = pdc_mem_pdt_read_entries(&pdt_read_ret, pdt_entry);
200 struct pdc_pat_mem_read_pd_retinfo pat_pret;
202 if (pdt_type == PDT_PAT_CELL)
203 ret = pdc_pat_mem_read_cell_pdt(&pat_pret, pdt_entry,
206 ret = pdc_pat_mem_read_pd_pdt(&pat_pret, pdt_entry,
207 MAX_PDT_TABLE_SIZE, 0);
215 pr_warn("PDT: Get PDT entries failed with %d\n", ret);
219 for (i = 0; i < pdt_status.pdt_entries; i++) {
222 report_mem_err(pdt_entry[i]);
224 addr = pdt_entry[i] & PDT_ADDR_PHYS_MASK;
225 if (IS_ENABLED(CONFIG_BLK_DEV_INITRD) &&
226 addr >= initrd_start && addr < initrd_end)
227 pr_crit("CRITICAL: initrd possibly broken "
228 "due to bad memory!\n");
230 /* mark memory page bad */
231 memblock_reserve(pdt_entry[i] & PAGE_MASK, PAGE_SIZE);
237 * This is the PDT kernel thread main loop.
240 static int pdt_mainloop(void *unused)
242 struct pdc_mem_read_pdt pdt_read_ret;
243 struct pdc_pat_mem_read_pd_retinfo pat_pret __maybe_unused;
244 unsigned long old_num_entries;
245 unsigned long *bad_mem_ptr;
249 set_current_state(TASK_INTERRUPTIBLE);
251 old_num_entries = pdt_status.pdt_entries;
253 schedule_timeout(pdt_poll_interval);
254 if (kthread_should_stop())
257 /* Do we have new PDT entries? */
260 ret = get_info_pat_new();
263 ret = get_info_pat_cell();
266 ret = pdc_mem_pdt_info(&pdt_status);
271 pr_warn("PDT: unexpected failure %d\n", ret);
275 /* if no new PDT entries, just wait again */
276 num = pdt_status.pdt_entries - old_num_entries;
280 /* decrease poll interval in case we found memory errors */
281 if (pdt_status.pdt_entries &&
282 pdt_poll_interval == PDT_POLL_INTERVAL_DEFAULT)
283 pdt_poll_interval = PDT_POLL_INTERVAL_SHORT;
285 /* limit entries to get */
286 if (num > MAX_PDT_ENTRIES) {
287 num = MAX_PDT_ENTRIES;
288 pdt_status.pdt_entries = old_num_entries + num;
291 /* get new entries */
295 if (pdt_status.pdt_entries > MAX_PDT_ENTRIES) {
296 pr_crit("PDT: too many entries.\n");
299 ret = pdc_pat_mem_read_cell_pdt(&pat_pret, pdt_entry,
301 bad_mem_ptr = &pdt_entry[old_num_entries];
304 ret = pdc_pat_mem_read_pd_pdt(&pat_pret,
306 num * sizeof(unsigned long),
307 old_num_entries * sizeof(unsigned long));
308 bad_mem_ptr = &pdt_entry[0];
312 ret = pdc_mem_pdt_read_entries(&pdt_read_ret,
314 bad_mem_ptr = &pdt_entry[old_num_entries];
318 /* report and mark memory broken */
320 unsigned long pde = *bad_mem_ptr++;
324 #ifdef CONFIG_MEMORY_FAILURE
325 if ((pde & PDT_ADDR_PERM_ERR) ||
326 ((pde & PDT_ADDR_SINGLE_ERR) == 0))
327 memory_failure(pde >> PAGE_SHIFT, 0, 0);
330 pfn_to_page(pde >> PAGE_SHIFT), 0);
332 pr_crit("PDT: memory error at 0x%lx ignored.\n"
333 "Rebuild kernel with CONFIG_MEMORY_FAILURE=y "
334 "for real handling.\n",
335 pde & PDT_ADDR_PHYS_MASK);
345 static int __init pdt_initcall(void)
347 struct task_struct *kpdtd_task;
349 if (pdt_type == PDT_NONE)
352 kpdtd_task = kthread_create(pdt_mainloop, NULL, "kpdtd");
353 if (IS_ERR(kpdtd_task))
354 return PTR_ERR(kpdtd_task);
356 wake_up_process(kpdtd_task);
361 late_initcall(pdt_initcall);