From owner-svn-src-head@freebsd.org Fri Oct 12 21:59:10 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B022E10CC32F; Fri, 12 Oct 2018 21:59:10 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 54DA077C63; Fri, 12 Oct 2018 21:59:10 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4A259253A6; Fri, 12 Oct 2018 21:59:10 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w9CLxA67097614; Fri, 12 Oct 2018 21:59:10 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w9CLxAOK097613; Fri, 12 Oct 2018 21:59:10 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <201810122159.w9CLxAOK097613@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Fri, 12 Oct 2018 21:59:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r339337 - head/sys/amd64/amd64 X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/amd64/amd64 X-SVN-Commit-Revision: 339337 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 12 Oct 2018 21:59:10 -0000 Author: mjg Date: Fri Oct 12 21:59:09 2018 New Revision: 339337 URL: https://svnweb.freebsd.org/changeset/base/339337 Log: amd64: employ MEMMOVE in copyin/copyout See r339205 for justification. Reviewed by: kib Approved by: re (gjb) Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D17526 Modified: head/sys/amd64/amd64/support.S Modified: head/sys/amd64/amd64/support.S ============================================================================== --- head/sys/amd64/amd64/support.S Fri Oct 12 19:44:19 2018 (r339336) +++ head/sys/amd64/amd64/support.S Fri Oct 12 21:59:09 2018 (r339337) @@ -576,14 +576,27 @@ END(fillw) .endif .endm +.macro COPYINOUT_BEGIN +.endm + +.macro COPYINOUT_END + movq %rax,PCB_ONFAULT(%r11) + POP_FRAME_POINTER +.endm + +.macro COPYINOUT_SMAP_END + SMAP_ENABLE smap=1 + COPYINOUT_END +.endm + /* * copyout(from_kernel, to_user, len) * %rdi, %rsi, %rdx */ .macro COPYOUT smap erms PUSH_FRAME_POINTER - movq PCPU(CURPCB),%r9 - movq $copy_fault,PCB_ONFAULT(%r9) + movq PCPU(CURPCB),%r11 + movq $copy_fault,PCB_ONFAULT(%r11) /* * Check explicitly for non-user addresses. If 486 write protection @@ -609,43 +622,27 @@ END(fillw) ja copy_fault /* - * Set up arguments for rep movs*. + * Set return value to zero. Remaining failure mode goes through + * copy_fault. */ + xorl %eax,%eax + + /* + * Set up arguments for MEMMOVE. + */ movq %rdi,%r8 movq %rsi,%rdi movq %r8,%rsi movq %rdx,%rcx - /* - * Set return value to zero. Remaining failure mode goes through - * copy_fault. - */ - xorl %eax,%eax SMAP_DISABLE \smap -.if \erms == 0 - cmpq $15,%rcx - jbe 1f - shrq $3,%rcx - rep - movsq - movb %dl,%cl - andb $7,%cl - jne 1f - SMAP_ENABLE \smap - movq %rax,PCB_ONFAULT(%r9) - POP_FRAME_POINTER - ret - ALIGN_TEXT -1: +.if \smap == 1 + MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_SMAP_END +.else + MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_END .endif - rep - movsb - - SMAP_ENABLE \smap - movq %rax,PCB_ONFAULT(%r9) - POP_FRAME_POINTER - ret + /* NOTREACHED */ .endm ENTRY(copyout_nosmap_std) @@ -670,8 +667,8 @@ END(copyout_smap_erms) */ .macro COPYIN smap erms PUSH_FRAME_POINTER - movq PCPU(CURPCB),%r9 - movq $copy_fault,PCB_ONFAULT(%r9) + movq PCPU(CURPCB),%r11 + movq $copy_fault,PCB_ONFAULT(%r11) /* * make sure address is valid @@ -683,37 +680,20 @@ END(copyout_smap_erms) cmpq %rcx,%rax ja copy_fault + xorl %eax,%eax + movq %rdi,%r8 movq %rsi,%rdi movq %r8,%rsi movq %rdx,%rcx - xorl %eax,%eax - SMAP_DISABLE \smap -.if \erms == 0 - cmpq $15,%rcx - jbe 1f - shrq $3,%rcx /* copy longword-wise */ - rep - movsq - movb %dl,%cl - andb $7,%cl /* copy remaining bytes */ - jne 1f - SMAP_ENABLE \smap - movq %rax,PCB_ONFAULT(%r9) - POP_FRAME_POINTER - ret - ALIGN_TEXT -1: +.if \smap == 1 + MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_SMAP_END +.else + MEMMOVE erms=\erms overlap=0 begin=COPYINOUT_BEGIN end=COPYINOUT_END .endif - rep - movsb - - SMAP_ENABLE \smap - movq %rax,PCB_ONFAULT(%r9) - POP_FRAME_POINTER - ret + /* NOTREACHED */ .endm ENTRY(copyin_nosmap_std) @@ -735,7 +715,7 @@ END(copyin_smap_erms) ALIGN_TEXT /* Trap entry clears PSL.AC */ copy_fault: - movq $0,PCB_ONFAULT(%r9) + movq $0,PCB_ONFAULT(%r11) movl $EFAULT,%eax POP_FRAME_POINTER ret