Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp128733pxy; Fri, 30 Apr 2021 01:48:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwVmTfXZkRqDy6VDWXSymj5Q7uMszXZZ9YuUoZgJVyhGaQw64Ia1ptNwmgShi+zkVHrNet/ X-Received: by 2002:a17:90a:ea11:: with SMTP id w17mr14228781pjy.6.1619772515268; Fri, 30 Apr 2021 01:48:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619772515; cv=none; d=google.com; s=arc-20160816; b=FTaojL1EnAnZGPnYnFGFaQtL5n88QOXtoz5p7MeWh4jV+2w6fY8RxOlY1YHO7cYgyz nkfjb/HuChswFrLnchRhQwZPsKbEZyfQPZK9BBVWCI0dSA9H5B0ZVTrCE68Ls9Xcu48E I/UILu2ogHErAk3p+tfYykLnh9x4piZ/9NGimjbAOECAZHQm3JGGLRG43xE0e5Uoem2c dAmtr0OutwyP1EENUZK/KKVJZatIhibhNkXpu+bmzaYtDnfj/WNUddepM/GzafKZjcDj gwkpPUxZmdVcvJOhJCyuyJKfkUroO+FwK4JFZqWpUT1O9X5cEHiwzSAwKvHfjA5SX0Ak w8sA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=FT4s6hLaq6i8rSbbuImH0wICk8s1enj6YEh+n2TcY30=; b=R8R5Mz/lYkxvHJzSXNdWzwAue24i3lZ66Rt0auI7NDZ4UZtLR/yYrnpy3K/HcvGS2O up6v2BfBAPgycalgMHEAercPBEUfH1yYcqC0mrIK5Cxt+XqD/KecL41j34ajBLHCFgal nqOVR3gFUyjUdWW8ecQkOHqbNhzstkmakRiTFpe+2jTetJHMyDLh77rhB20XptY1lrDF Ow68Kh/FNNhJaws3G2zmmpYDk9ROTVqK/p6lEIb0+NFQUEajjEqFFxeFMJDC6Lb8obkR YtvZK4HjenP+O1xg/LscWVU9uiUnacsZec12yy3GvZpI2GEozdKnxSphmNyM1tOmMCW4 KV0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n38si2752527pgl.142.2021.04.30.01.48.21; Fri, 30 Apr 2021 01:48:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229601AbhD3Is3 (ORCPT + 99 others); Fri, 30 Apr 2021 04:48:29 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:39929 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbhD3Is3 (ORCPT ); Fri, 30 Apr 2021 04:48:29 -0400 Received: from localhost (mailhub3.si.c-s.fr [192.168.12.233]) by localhost (Postfix) with ESMTP id 4FWmGN0sRgz9wct; Fri, 30 Apr 2021 10:47:40 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Sa6dCHscddjg; Fri, 30 Apr 2021 10:47:40 +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 4FWmGM728Qz9wc9; Fri, 30 Apr 2021 10:47:39 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id DF53F8B87E; Fri, 30 Apr 2021 10:47:39 +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 EiSgWgqkncLp; Fri, 30 Apr 2021 10:47:39 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 602258B87A; Fri, 30 Apr 2021 10:47:39 +0200 (CEST) Subject: Re: [PATCH 1/3] lib: early_string: allow early usage of some string functions To: Daniel Walker , linuxppc-dev@lists.ozlabs.org, x86@kernel.org, Andrew Morton Cc: xe-linux-external@cisco.com, linux-kernel@vger.kernel.org References: <20210430042217.1198052-1-danielwa@cisco.com> From: Christophe Leroy Message-ID: Date: Fri, 30 Apr 2021 10:47:39 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.0 MIME-Version: 1.0 In-Reply-To: <20210430042217.1198052-1-danielwa@cisco.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 30/04/2021 à 06:22, Daniel Walker a écrit : > This systems allows some string functions to be moved into > lib/early_string.c and they will be prepended with "early_" and compiled > without debugging like KASAN. > > This is already done on x86 for, > "AMD Secure Memory Encryption (SME) support" > > and on powerpc prom_init.c , and EFI's libstub. > > The AMD memory feature disabled KASAN for all string functions, and > prom_init.c and efi libstub implement their own versions of the > functions. > > This implementation allows sharing of the string functions without > removing the debugging features for the whole system. This looks good. I prefer that rather than the way you proposed to do it two years ago. Only one problem, see below. > +size_t strlcat(char *dest, const char *src, size_t count) > +{ > + size_t dsize = strlen(dest); > + size_t len = strlen(src); > + size_t res = dsize + len; > + > + /* This would be a bug */ > + BUG_ON(dsize >= count); powerpc is not ready to handle BUG_ON() in when in prom_init. Can you do: #ifndef __EARLY_STRING_ENABLED BUG_ON(dsize >= count); #endif > + > + dest += dsize; > + count -= dsize; > + if (len >= count) > + len = count-1; > + memcpy(dest, src, len); > + dest[len] = 0; > + return res; > +} > +EXPORT_SYMBOL(strlcat); > +#endif > +