From patchwork Tue Apr 17 07:38:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 899116 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40QHKK2Vjyz9s19 for ; Tue, 17 Apr 2018 17:42:45 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 40QHKK0v87zF244 for ; Tue, 17 Apr 2018 17:42:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=c-s.fr (client-ip=93.17.236.30; helo=pegase1.c-s.fr; envelope-from=christophe.leroy@c-s.fr; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=c-s.fr Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 40QHDd52nKzF1yy for ; Tue, 17 Apr 2018 17:38:41 +1000 (AEST) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 40QHDQ03Bwz9ty7t; Tue, 17 Apr 2018 09:38:30 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id kiGA3rys7-qe; Tue, 17 Apr 2018 09:38:29 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 40QHDP5cRcz9ty7q; Tue, 17 Apr 2018 09:38:29 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id E9DC78B884; Tue, 17 Apr 2018 09:38:37 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id tWnyEl6tbXC4; Tue, 17 Apr 2018 09:38:37 +0200 (CEST) Received: from po15720vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.2]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6BEA58B887; Tue, 17 Apr 2018 09:38:37 +0200 (CEST) Received: by po15720vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 63D656C030; Tue, 17 Apr 2018 09:38:37 +0200 (CEST) Message-Id: In-Reply-To: References: From: Christophe Leroy Subject: [PATCH 2/7] powerpc/lib: inline memcmp() NUL size verification To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Date: Tue, 17 Apr 2018 09:38:37 +0200 (CEST) X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Many calls to memcmp() are done with constant size. This patch gives GCC a chance to optimise out the NULL size verification. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/string.h | 10 ++++++++++ arch/powerpc/lib/memcmp_64.S | 4 ++++ arch/powerpc/lib/string_32.S | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/arch/powerpc/include/asm/string.h b/arch/powerpc/include/asm/string.h index 9b8cedf618f4..cf6f495134c3 100644 --- a/arch/powerpc/include/asm/string.h +++ b/arch/powerpc/include/asm/string.h @@ -27,6 +27,16 @@ extern int memcmp(const void *,const void *,__kernel_size_t); extern void * memchr(const void *,int,__kernel_size_t); extern void * memcpy_flushcache(void *,const void *,__kernel_size_t); +#ifndef CONFIG_FORTIFY_SOURCE +static inline int __memcmp(const void *p,const void *q,__kernel_size_t size) +{ + if (unlikely(!size)) + return 0; + return memcmp(p, q, size); +} +#define memcmp __memcmp +#endif + #ifdef CONFIG_PPC64 #define __HAVE_ARCH_MEMSET32 #define __HAVE_ARCH_MEMSET64 diff --git a/arch/powerpc/lib/memcmp_64.S b/arch/powerpc/lib/memcmp_64.S index d75d18b7bd55..f6822fabf254 100644 --- a/arch/powerpc/lib/memcmp_64.S +++ b/arch/powerpc/lib/memcmp_64.S @@ -30,7 +30,9 @@ #endif _GLOBAL(memcmp) +#ifdef CONFIG_FORTIFY_SOURCE cmpdi cr1,r5,0 +#endif /* Use the short loop if both strings are not 8B aligned */ or r6,r3,r4 @@ -39,7 +41,9 @@ _GLOBAL(memcmp) /* Use the short loop if length is less than 32B */ cmpdi cr6,r5,31 +#ifdef CONFIG_FORTIFY_SOURCE beq cr1,.Lzero +#endif bne .Lshort bgt cr6,.Llong diff --git a/arch/powerpc/lib/string_32.S b/arch/powerpc/lib/string_32.S index 2519f8bd09e3..94e9c9bc31c3 100644 --- a/arch/powerpc/lib/string_32.S +++ b/arch/powerpc/lib/string_32.S @@ -15,8 +15,10 @@ .text _GLOBAL(memcmp) +#ifdef CONFIG_FORTIFY_SOURCE PPC_LCMPI 0,r5,0 beq- 2f +#endif mtctr r5 addi r6,r3,-1 addi r4,r4,-1 @@ -25,8 +27,10 @@ _GLOBAL(memcmp) subf. r3,r0,r3 bdnzt 2,1b blr +#ifdef CONFIG_FORTIFY_SOURCE 2: li r3,0 blr +#endif EXPORT_SYMBOL(memcmp) _GLOBAL(__clear_user)