Add support for memcpy_mcsafe
cover Add support for memcpy_mcsafe
memcpy_mcsafe() is an API currently used by the pmem subsystem to convert errors while doing a memcpy (machine check exception errors) to a return value. This patchset consists of three patches
1. The first patch is a bug fix to handle machine check errors correctly while walking the page tables in kernel mode, due to huge pmd/pud sizes
2. The second patch adds memcpy_mcsafe() support, this is largely derived from existing code
3. The third patch registers for callbacks on machine check exceptions and in them uses specialized knowledge of the type of page to decide whether to handle the MCE as is or to return to a fixup address present in memcpy_mcsafe(). If a fixup address is used, then we return an error value of -EFAULT to the caller.
Testing
A large part of the testing was done under a simulator by selectively inserting machine check exceptions in a test driver doing memcpy_mcsafe via ioctls.
Balbir Singh (3):
powerpc/mce: Bug fixes for MCE handling in kernel space powerpc/memcpy: Add memcpy_mcsafe for pmem powerpc/mce: Handle memcpy_mcsafe
arch/powerpc/include/asm/mce.h | 3 +- arch/powerpc/include/asm/string.h | 2 + arch/powerpc/kernel/mce.c | 76 +++++++++++- arch/powerpc/kernel/mce_power.c | 17 +-- arch/powerpc/lib/Makefile | 2 +- arch/powerpc/lib/memcpy_mcsafe_64.S | 225 ++++++++++++++++++++++++++++++++++++ 6 files changed, 314 insertions(+), 11 deletions(-) create mode 100644 arch/powerpc/lib/memcpy_mcsafe_64.S
Signature · 1 line
2.13.6
RFC 1/3 powerpc/mce: Bug fixes for MCE handling in kernel space
The code currently assumes PAGE_SHIFT as the shift value of the pfn, this works correctly (mostly) for user space pages, but the correct thing to do is
1. Extrace the shift value returned via the pte-walk API's
2. Use the shift value to access the instruction address.
Note, the final physical address still use PAGE_SHIFT for computation. handle_ierror() is not modified and handle_derror() is modified just for extracting the correct instruction address.
--- arch/powerpc/kernel/mce_power.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
arch/powerpc/kernel/mce_power.c +10 -7
@@ -36,7 +36,8 @@* Convert an address related to an mm to a PFN. NOTE: we are in real * mode, we could potentially race with page table updates. */ -static unsigned long addr_to_pfn (struct pt_regs *regs,unsigned long addr) +static unsigned long addr_to_pfn (struct pt_regs *regs,unsigned long addr, +unsigned int *shift) {pte_t *ptep;unsigned long flags;
@@ -49,9 +50,9 @@ static unsigned long addr_to_pfn(struct pt_regs *regs, unsigned long addr)local_irq_save (flags);if (mm == current->mm) - ptep =find_current_mm_pte (mm->pgd, addr,NULL ,NULL ); + ptep =find_current_mm_pte (mm->pgd, addr,NULL , shift);else - ptep =find_init_mm_pte (addr,NULL ); + ptep =find_init_mm_pte (addr, shift);local_irq_restore (flags);if (!ptep ||pte_special (*ptep))return ULONG_MAX ;
@@ -353,13 +354,14 @@ static int mce_find_instr_ea_and_pfn(struct pt_regs *regs, uint64_t *addr,unsigned long pfn, instr_addr;struct instruction_op op;struct pt_regs tmp = *regs; +unsigned int shift; - pfn =addr_to_pfn (regs, regs->nip); + pfn =addr_to_pfn (regs, regs->nip, &shift);if (pfn !=ULONG_MAX ) { - instr_addr = (pfn <<PAGE_SHIFT ) + (regs->nip & ~PAGE_MASK ); + instr_addr = (pfn << shift) + (regs->nip & ((1 << shift) -1 )); instr = *(unsigned int *)(instr_addr);if (!analyse_instr (&op, &tmp, instr)) { - pfn =addr_to_pfn (regs, op.ea); + pfn =addr_to_pfn (regs, op.ea, &shift); *addr = op.ea; *phys_addr = (pfn <<PAGE_SHIFT );return 0 ;
@@ -437,7 +439,8 @@ static int mce_handle_ierror(struct pt_regs *regs,unsigned long pfn;if (get_paca ()->in_mce <MAX_MCE_DEPTH ) { - pfn =addr_to_pfn (regs, regs->nip); + pfn =addr_to_pfn (regs, regs->nip, +NULL );if (pfn !=ULONG_MAX ) { *phys_addr = (pfn <<PAGE_SHIFT );
Signature · 1 line
2.13.6
RFC 2/3 powerpc/memcpy: Add memcpy_mcsafe for pmem
In reply to Balbir SinghThe pmem infrastructure uses memcpy_mcsafe in the pmem layer so as to convert machine check excpetions into a return value on failure in case a machine check exception is encoutered during the memcpy.
This patch largely borrows from the copyuser_power7 logic and does not add the VMX optimizations, largely to keep the patch simple. If needed those optimizations can be folded in.
--- arch/powerpc/include/asm/string.h | 2 + arch/powerpc/lib/Makefile | 2 +- arch/powerpc/lib/memcpy_mcsafe_64.S | 212 ++++++++++++++++++++++++++++++++++++ 3 files changed, 215 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/lib/memcpy_mcsafe_64.S
arch/powerpc/include/asm/string.h +2 -0
@@ -30,7 +30,9 @@ extern void * memcpy_flushcache(void *,const void *,__kernel_size_t);#ifdef CONFIG_PPC64 #define __HAVE_ARCH_MEMSET32#define __HAVE_ARCH_MEMSET64 +#define __HAVE_ARCH_MEMCPY_MCSAFE +extern int memcpy_mcsafe (void *dst,const void *src,__kernel_size_t sz);extern void *__memset16 (uint16_t *,uint16_t v,__kernel_size_t );extern void *__memset32 (uint32_t *,uint32_t v,__kernel_size_t );extern void *__memset64 (uint64_t *,uint64_t v,__kernel_size_t );
arch/powerpc/lib/Makefile +1 -1
@@ -24,7 +24,7 @@ endif obj64-y += copypage_64.o copyuser_64.o mem_64.o hweight_64.o \ copyuser_power7.o string_64.o copypage_power7.o memcpy_power7.o \ - memcpy_64.o memcmp_64.o pmem.o + memcpy_64.o memcmp_64.o pmem.o memcpy_mcsafe_64.o obj64-$(CONFIG_SMP) += locks.o obj64-$(CONFIG_ALTIVEC) += vmx-helper.o
arch/powerpc/lib/memcpy_mcsafe_64.S new file +212 -0
212 lines not on this page · raw message
Signature · 1 line
2.13.6
RFC 3/3 powerpc/mce: Handle memcpy_mcsafe
In reply to Balbir SinghAdd a blocking notifier callback to be called in real-mode on machine check exceptions for UE (ld/st) errors only. The patch registers a callback on boot to be notified of machine check exceptions and returns a NOTIFY_STOP when a page of interest is seen as the source of the machine check exception. This page of interest is a ZONE_DEVICE page and hence for now, for memcpy_mcsafe to work, the page needs to belong to ZONE_DEVICE and memcpy_mcsafe should be used to access the memory.
The patch also modifies the NIP of the exception context to go back to the fixup handler (in memcpy_mcsafe) and does not print any error message as the error is treated as returned via a return value and handled.
--- arch/powerpc/include/asm/mce.h | 3 +- arch/powerpc/kernel/mce.c | 77 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 77 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/mce.h +2 -1
@@ -125,7 +125,8 @@ struct machine_check_event { enum MCE_UeErrorType ue_error_type:8;uint8_t effective_address_provided;uint8_t physical_address_provided; -uint8_t reserved_1[5 ]; +uint8_t error_return; +uint8_t reserved_1[4 ];uint64_t effective_address;uint64_t physical_address;uint8_t reserved_2[8 ];
arch/powerpc/kernel/mce.c +75 -2
110 lines not on this page · raw message
Signature · 1 line
2.13.6