Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp3553884ybl; Mon, 12 Aug 2019 02:25:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqzXTOgQZsEYKsatqRRjFcyHkfkFzs0uOySdJRjqoMNRGvibMb9YktpPg+kxVsS+yVqGT0Ny X-Received: by 2002:aa7:8193:: with SMTP id g19mr33948333pfi.16.1565601906832; Mon, 12 Aug 2019 02:25:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565601906; cv=none; d=google.com; s=arc-20160816; b=AW4fa5Le0trd6zVexJVZI+IZ9kdX2pS4LaCk+lYBDX9Px6cP03b/HfCiH770UngmBF emc5VLV4ytBfmL125drxCrwNDmfwpeWHCifkAqp7LjwHBhr8qTWksQMtN69eAoZi1eE4 wDdpAHCbDqLHXs98PayGona67oTUhWW/lTNZDhi7/DPJuDQztZMN/UodBrn+Pdu5pLwC 1DyGNbZuZmgswGRHclKmgN9D0WPwTgdVcWwbSq02AUCeCntJ5xJS6cqfYCo51sEixclv TPUnnxLe+x8cnCglsnQQfSerX97Ykt40bTxS3ENWuBRoiAomua74TKqe9x3DcPRRbjiU dKrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=2Wzd0oM19a1Y2XLWndwD600p9ctH3XimEIED6JZrwmc=; b=NdPm3bWfAAqho3Zf+E/2MXC1fcglT1+HY98yG827x3IBLVO98HJqT+34ioB4Kg2D8t 22w028xztMLSIl12mAk/fLRep6k7FuLIsdlmCVgGi648Ejhpl5EgEm5uHHZLbIJwbloy HIPuOb1xyiozjEUN0i7OsZiMTccos9OnDHC27bjTeF9NzpWfgkaWPH59bUjHALnSnui5 6zsVWPQTx3hZ8rZjMlbCwdhR0BL8k2Y0nQ0FGDdm9Jm7B1bECV93NO8iAyKtv5mkRUuD KyVHhE0+ovMJu1YEIW8+t15di5mFR4qe+lem4jpfSAaZpzoiN2C1FwJg7JJc9Zu7W1Dn 4tvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@fossix-org.20150623.gappssmtp.com header.s=20150623 header.b=SGEWTiCZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b25si68814133pgl.270.2019.08.12.02.24.51; Mon, 12 Aug 2019 02:25:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fossix-org.20150623.gappssmtp.com header.s=20150623 header.b=SGEWTiCZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727505AbfHLJXN (ORCPT + 99 others); Mon, 12 Aug 2019 05:23:13 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:40973 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727369AbfHLJXL (ORCPT ); Mon, 12 Aug 2019 05:23:11 -0400 Received: by mail-pl1-f196.google.com with SMTP id m9so47479687pls.8 for ; Mon, 12 Aug 2019 02:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fossix-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2Wzd0oM19a1Y2XLWndwD600p9ctH3XimEIED6JZrwmc=; b=SGEWTiCZ77eLyOBayPTpPVTXo3Mn40TS3ekgqgDcQlnQYC3gPv+Sl9FEpCihYjH4jo PyPzhrH8Xi091GLdHU1peWUPVmRYpMY3bB9WjZBV9J3129p3+BK2Am24dPrEXmlIaGSF c7e0gdlz9cR789PCpEaU+2S/uj0YdgJlqwrBOnPd1uBRc7RiSVEDzSBXDPwxoN1BpA7y EGHxgJxVVosGz0tgCLgxaNqxiK6R37vX7GKXV/WcJEDtQdm91gLEeKoaAzTN+BlS6poG y6gycA2OpZQi8BLSue1U7bsHtSV9ISkf5ZvqYQPIcmhvFzDjWVAuydUEUAc+lmFqs/JV Xpqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2Wzd0oM19a1Y2XLWndwD600p9ctH3XimEIED6JZrwmc=; b=HnmLfEcvBhu7FJaeAxE3ujM2tPw9GFCQ738UAA5ZoKZTEZwVIfkcS9vyzbrITKre/z iYEEnjwrYtUnDbL67/v3+BEXad4EletUA6Frlw1MGE5Cu0VTFD6OrGsPyj2MBy6CC0Jg kNn/Uut+nI6iaGj86NRWxBIBkWMWHowUyICf7J/gj0L8peNHwlbzS2fqfzXchsRx6QWP HV4gHZb7d2tQ2L9GAlibOKltYxvHFUS9qJceUO+P2kN6m6kZRSchKHKYGEbdHQnVs/v/ rfJF8k4u2K8HItJozlbAl3sbXWKOarGewJsRy2Xb/cYOr0Lg2rchdjrmOLmQR0RT2Zfp m4Zg== X-Gm-Message-State: APjAAAXj4YPfGBnByL1PQUe/3T4N+o7KgIYhYKNtrLmKqFQ6AEh7YNZl /WOx9t11Zqra6x299XFh+IGTQg== X-Received: by 2002:a17:902:e58b:: with SMTP id cl11mr31174163plb.24.1565601790269; Mon, 12 Aug 2019 02:23:10 -0700 (PDT) Received: from santosiv.in.ibm.com ([129.41.84.75]) by smtp.gmail.com with ESMTPSA id y188sm10543517pfb.115.2019.08.12.02.23.07 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 12 Aug 2019 02:23:09 -0700 (PDT) From: Santosh Sivaraj To: linuxppc-dev , Linux Kernel Cc: "Aneesh Kumar K.V" , Mahesh Salgaonkar , Reza Arbab , Balbir Singh , Chandan Rajendra , Michael Ellerman , Nicholas Piggin , christophe leroy Subject: [PATCH v9 5/7] powerpc/memcpy: Add memcpy_mcsafe for pmem Date: Mon, 12 Aug 2019 14:52:34 +0530 Message-Id: <20190812092236.16648-6-santosh@fossix.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190812092236.16648-1-santosh@fossix.org> References: <20190812092236.16648-1-santosh@fossix.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Balbir Singh The pmem infrastructure uses memcpy_mcsafe in the pmem layer so as to convert machine check exceptions into a return value on failure in case a machine check exception is encountered during the memcpy. The return value is the number of bytes remaining to be copied. 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. Signed-off-by: Balbir Singh [arbab@linux.ibm.com: Added symbol export] Co-developed-by: Santosh Sivaraj Signed-off-by: Santosh Sivaraj --- arch/powerpc/include/asm/string.h | 2 + arch/powerpc/lib/Makefile | 2 +- arch/powerpc/lib/memcpy_mcsafe_64.S | 242 ++++++++++++++++++++++++++++ 3 files changed, 245 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/lib/memcpy_mcsafe_64.S diff --git a/arch/powerpc/include/asm/string.h b/arch/powerpc/include/asm/string.h index 9bf6dffb4090..b72692702f35 100644 --- a/arch/powerpc/include/asm/string.h +++ b/arch/powerpc/include/asm/string.h @@ -53,7 +53,9 @@ void *__memmove(void *to, const void *from, __kernel_size_t n); #ifndef CONFIG_KASAN #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); diff --git a/arch/powerpc/lib/Makefile b/arch/powerpc/lib/Makefile index eebc782d89a5..fa6b1b657b43 100644 --- a/arch/powerpc/lib/Makefile +++ b/arch/powerpc/lib/Makefile @@ -39,7 +39,7 @@ obj-$(CONFIG_PPC_BOOK3S_64) += copyuser_power7.o copypage_power7.o \ memcpy_power7.o obj64-y += copypage_64.o copyuser_64.o mem_64.o hweight_64.o \ - memcpy_64.o pmem.o + memcpy_64.o pmem.o memcpy_mcsafe_64.o obj64-$(CONFIG_SMP) += locks.o obj64-$(CONFIG_ALTIVEC) += vmx-helper.o diff --git a/arch/powerpc/lib/memcpy_mcsafe_64.S b/arch/powerpc/lib/memcpy_mcsafe_64.S new file mode 100644 index 000000000000..949976dc115d --- /dev/null +++ b/arch/powerpc/lib/memcpy_mcsafe_64.S @@ -0,0 +1,242 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) IBM Corporation, 2011 + * Derived from copyuser_power7.s by Anton Blanchard + * Author - Balbir Singh + */ +#include +#include +#include + + .macro err1 +100: + EX_TABLE(100b,.Ldo_err1) + .endm + + .macro err2 +200: + EX_TABLE(200b,.Ldo_err2) + .endm + + .macro err3 +300: EX_TABLE(300b,.Ldone) + .endm + +.Ldo_err2: + ld r22,STK_REG(R22)(r1) + ld r21,STK_REG(R21)(r1) + ld r20,STK_REG(R20)(r1) + ld r19,STK_REG(R19)(r1) + ld r18,STK_REG(R18)(r1) + ld r17,STK_REG(R17)(r1) + ld r16,STK_REG(R16)(r1) + ld r15,STK_REG(R15)(r1) + ld r14,STK_REG(R14)(r1) + addi r1,r1,STACKFRAMESIZE +.Ldo_err1: + /* Do a byte by byte copy to get the exact remaining size */ + mtctr r7 +46: +err3; lbz r0,0(r4) + addi r4,r4,1 +err3; stb r0,0(r3) + addi r3,r3,1 + bdnz 46b + li r3,0 + blr + +.Ldone: + mfctr r3 + blr + + +_GLOBAL(memcpy_mcsafe) + mr r7,r5 + cmpldi r5,16 + blt .Lshort_copy + +.Lcopy: + /* Get the source 8B aligned */ + neg r6,r4 + mtocrf 0x01,r6 + clrldi r6,r6,(64-3) + + bf cr7*4+3,1f +err1; lbz r0,0(r4) + addi r4,r4,1 +err1; stb r0,0(r3) + addi r3,r3,1 + subi r7,r7,1 + +1: bf cr7*4+2,2f +err1; lhz r0,0(r4) + addi r4,r4,2 +err1; sth r0,0(r3) + addi r3,r3,2 + subi r7,r7,2 + +2: bf cr7*4+1,3f +err1; lwz r0,0(r4) + addi r4,r4,4 +err1; stw r0,0(r3) + addi r3,r3,4 + subi r7,r7,4 + +3: sub r5,r5,r6 + cmpldi r5,128 + blt 5f + + mflr r0 + stdu r1,-STACKFRAMESIZE(r1) + std r14,STK_REG(R14)(r1) + std r15,STK_REG(R15)(r1) + std r16,STK_REG(R16)(r1) + std r17,STK_REG(R17)(r1) + std r18,STK_REG(R18)(r1) + std r19,STK_REG(R19)(r1) + std r20,STK_REG(R20)(r1) + std r21,STK_REG(R21)(r1) + std r22,STK_REG(R22)(r1) + std r0,STACKFRAMESIZE+16(r1) + + srdi r6,r5,7 + mtctr r6 + + /* Now do cacheline (128B) sized loads and stores. */ + .align 5 +4: +err2; ld r0,0(r4) +err2; ld r6,8(r4) +err2; ld r8,16(r4) +err2; ld r9,24(r4) +err2; ld r10,32(r4) +err2; ld r11,40(r4) +err2; ld r12,48(r4) +err2; ld r14,56(r4) +err2; ld r15,64(r4) +err2; ld r16,72(r4) +err2; ld r17,80(r4) +err2; ld r18,88(r4) +err2; ld r19,96(r4) +err2; ld r20,104(r4) +err2; ld r21,112(r4) +err2; ld r22,120(r4) + addi r4,r4,128 +err2; std r0,0(r3) +err2; std r6,8(r3) +err2; std r8,16(r3) +err2; std r9,24(r3) +err2; std r10,32(r3) +err2; std r11,40(r3) +err2; std r12,48(r3) +err2; std r14,56(r3) +err2; std r15,64(r3) +err2; std r16,72(r3) +err2; std r17,80(r3) +err2; std r18,88(r3) +err2; std r19,96(r3) +err2; std r20,104(r3) +err2; std r21,112(r3) +err2; std r22,120(r3) + addi r3,r3,128 + subi r7,r7,128 + bdnz 4b + + clrldi r5,r5,(64-7) + + /* Up to 127B to go */ +5: srdi r6,r5,4 + mtocrf 0x01,r6 + +6: bf cr7*4+1,7f +err2; ld r0,0(r4) +err2; ld r6,8(r4) +err2; ld r8,16(r4) +err2; ld r9,24(r4) +err2; ld r10,32(r4) +err2; ld r11,40(r4) +err2; ld r12,48(r4) +err2; ld r14,56(r4) + addi r4,r4,64 +err2; std r0,0(r3) +err2; std r6,8(r3) +err2; std r8,16(r3) +err2; std r9,24(r3) +err2; std r10,32(r3) +err2; std r11,40(r3) +err2; std r12,48(r3) +err2; std r14,56(r3) + addi r3,r3,64 + subi r7,r7,64 + +7: ld r14,STK_REG(R14)(r1) + ld r15,STK_REG(R15)(r1) + ld r16,STK_REG(R16)(r1) + ld r17,STK_REG(R17)(r1) + ld r18,STK_REG(R18)(r1) + ld r19,STK_REG(R19)(r1) + ld r20,STK_REG(R20)(r1) + ld r21,STK_REG(R21)(r1) + ld r22,STK_REG(R22)(r1) + addi r1,r1,STACKFRAMESIZE + + /* Up to 63B to go */ + bf cr7*4+2,8f +err1; ld r0,0(r4) +err1; ld r6,8(r4) +err1; ld r8,16(r4) +err1; ld r9,24(r4) + addi r4,r4,32 +err1; std r0,0(r3) +err1; std r6,8(r3) +err1; std r8,16(r3) +err1; std r9,24(r3) + addi r3,r3,32 + subi r7,r7,32 + + /* Up to 31B to go */ +8: bf cr7*4+3,9f +err1; ld r0,0(r4) +err1; ld r6,8(r4) + addi r4,r4,16 +err1; std r0,0(r3) +err1; std r6,8(r3) + addi r3,r3,16 + subi r7,r7,16 + +9: clrldi r5,r5,(64-4) + + /* Up to 15B to go */ +.Lshort_copy: + mtocrf 0x01,r5 + bf cr7*4+0,12f +err1; lwz r0,0(r4) /* Less chance of a reject with word ops */ +err1; lwz r6,4(r4) + addi r4,r4,8 +err1; stw r0,0(r3) +err1; stw r6,4(r3) + addi r3,r3,8 + subi r7,r7,8 + +12: bf cr7*4+1,13f +err1; lwz r0,0(r4) + addi r4,r4,4 +err1; stw r0,0(r3) + addi r3,r3,4 + subi r7,r7,4 + +13: bf cr7*4+2,14f +err1; lhz r0,0(r4) + addi r4,r4,2 +err1; sth r0,0(r3) + addi r3,r3,2 + subi r7,r7,2 + +14: bf cr7*4+3,15f +err1; lbz r0,0(r4) +err1; stb r0,0(r3) + +15: li r3,0 + blr + +EXPORT_SYMBOL_GPL(memcpy_mcsafe); -- 2.21.0