summaryrefslogtreecommitdiff
tag namedax-zeroinit-clear-poison-5.15_2021-08-17 (202b5e5ef11fc11f62f5da503e982f269e6ac093)
tag date2021-08-17 16:39:34 -0700
tagged byDarrick J. Wong <djwong@kernel.org>
tagged objectcommit 47230dcee2...
dax: fix broken pmem poison narrative
Our current "advice" to people using persistent memory and FSDAX who wish to recover upon receipt of a media error (aka 'hwpoison') event from ACPI is to punch-hole that part of the file and then pwrite it, which will magically cause the pmem to be reinitialized and the poison to be cleared. Punching doesn't make any sense at all -- we don't allow userspace to allocate from specific parts of the storage, and another writer could grab the poisoned range in the meantime. In other words, the advice is seriously overfitted to incidental xfs and ext4 behavior and can completely fail. Worse yet, that concurrent writer now has to deal with the poison that it didn't know about, and someone else is trying to fix. AFAICT, the only reason why the "punch and write" dance works at all is that the XFS and ext4 currently call blkdev_issue_zeroout when allocating pmem as part of a pwrite call. A pwrite without the punch won't clear the poison, because pwrite on a DAX file calls dax_direct_access to access the memory directly, and dax_direct_access is only smart enough to bail out on poisoned pmem. It does not know how to clear it. Userspace could solve the problem by calling FIEMAP and issuing a BLKZEROOUT, but that requires rawio capabilities. The whole pmem poison recovery story is is wrong and needs to be corrected ASAP before everyone else starts doing this. Therefore, create a dax_zeroinit_range function that filesystems can call to reset the contents of the pmem to a known value and clear any state associated with the media error. Then, connect FALLOC_FL_ZERO_RANGE to this new function (for DAX files) so that unprivileged userspace has a safe way to reset the pmem and clear media errors. This is a sample copy of a SIGBUS handler that will dump out the siginfo data, call ZERO_RANGE to clear the poison, and then simulates being fortunate enough to be able to reconstruct the file contents from scratch. Note that I haven't tested this even with simulated pmem because I cannot figure out how to inject a poison error into the pmem in such a way that the nvdimm driver records it in the badblocks table. madvise(HWPOISON) calls the SIGBUS handler, but that code path never goes outside of the memory manager. int fd = open(...); char *data = mmap(fd, ... MAP_SYNC); static void handle_sigbus(int signal, siginfo_t *info, void *dontcare) { char *buf; loff_t err_offset = (char *)info->si_addr - data; loff_t err_len = (1ULL << info->si_addr_lsb); ssize_t ret; printf("RECEIVED SIGBUS (POISON HANDLER)! "); printf(" signal %d ", info->si_signo); printf(" errno %d ", info->si_errno); printf(" addr %p ", info->si_addr); printf(" addr_lsb %d ", info->si_addr_lsb); if (info->si_signo != SIGBUS) { printf(" code 0x%x ", info->si_code); return; } switch (info->si_code) { case BUS_ADRALN: printf(" code: BUS_ADRALN "); break; case BUS_ADRERR: printf(" code: BUS_ADRERR "); break; case BUS_OBJERR: printf(" code: BUS_OBJERR "); break; case BUS_MCEERR_AR: printf(" code: BUS_MCEERR_AR "); break; case BUS_MCEERR_AO: printf(" code: BUS_MCEERR_AO "); break; default: printf(" code 0x%x ", info->si_code); break; } printf(" err_offset %lld ", (unsigned long long)err_offset); printf(" err_len %lld ", (unsigned long long)err_len); if (info->si_code != BUS_MCEERR_AR) return; /* clear poison and reset pmem to initial value */ ret = fallocate(fd, FALLOC_FL_ZERO_RANGE, err_offset, err_len); if (ret) { perror("fallocate"); exit(9); } /* simulate being lucky enough to be able to reconstruct the data */ buf = malloc(err_len); if (!buf) { perror("malloc pwrite buf"); exit(10); } memset(buf, 0x59, err_len); ret = pwrite(fd, buf, err_len, err_offset); if (ret < 0) { perror("pwrite"); exit(11); } if (ret != err_len) { fprintf(stderr, "short write %zd bytes, wanted %lld ", ret, (long long)err_len); exit(12); } free(buf); } --- v2: fix some build robot complaints, add kerneldoc comments for the dax code -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEUzaAxoMeQq6m2jMV+H93GTRKtOsFAmEcSLYACgkQ+H93GTRK tOtCvQ//RNOfoA+Vqolu72AavJnIgRZY+I9FORVDLzr3NhYMvZHQGSOq/mlt25A8 QeeCJcxp7ctRVMFCi9AO2J7hVUpGpzuvC17qRypv2uwD58pwu/GJ8hF6JHg9kVqv +tEvLfTbaZwoI4UCN96cDGm+xBUhBi/u4bMYSMFN3WNOSGG8CQFdTCC1qAb3uASu SDpMmnqxJMzsYW7SyWYV46RnxvGFebhUMuQm+ppSNNc5z6IPeHF9ulbNhLJyx1Ir dUewuraFe+qmUpLnzFUEUA0lqMiG9MEq9dWjBO97F+llSaviDYPkFa6Q1sBAhbw2 oMtizjZk77M8ZZwbvUOS4B+7t/po0rRVLF1FDWno/Ua2HHpflQFLYQ0V3WemkD1G pJrBGs9VNGSeUxiY1H2MiceSIr+uXEDLuopCoOC+hLbh3tQzPNK9ghKGMJzD7STM 8X0DeiW0huj1CFYY9NxyAC2WRjN7UdkV0J37n/+n+hWuVV7JS79b4n/wKKBbxivz rxNbHEo5LdNIgqoRfag9RKlD2Es7UUuoIUmwLh/D42BHx9Kqq20JB2vGPq9tQXaq cwLYshEwBzsMHWqrTHl41DfaxYDlcAXraddg8tdFaZLhwZBaHWdGUmbOFW05pA2g HIx5diUQoLZjoPf1UMrk8Fm8kCD+pPzAOMEwHI7t+76vhZ1Oe7g= =aIix -----END PGP SIGNATURE-----