Received: by 2002:a05:6a10:a852:0:0:0:0 with SMTP id d18csp1014282pxy; Sat, 1 May 2021 00:52:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvdbfYwWXxMlYIfMRO2iD8ZZEdLX3Dd2LNvihVj7ZEHowsrmgDEo25it2c7O9c69yB/D4v X-Received: by 2002:a17:906:478c:: with SMTP id cw12mr8125502ejc.5.1619855527954; Sat, 01 May 2021 00:52:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619855527; cv=none; d=google.com; s=arc-20160816; b=kNGf5GAx/drGYY7RwojaFglUEjf0kRU0qXL6QkcTnIByFM+Pz0MSRTR5SJ/cDEv8rH 5TPC95O1kte+83Q+sYxHh3aNj/rpajXMgLHZUxJ8a6CezcHXbNDdPo7nsEw+VJzz07Ft /PnJVBtEbZWVl5fkaJCWMUW9ZVESw+cugj1HatDTeTKytCz327wic7hMLrHWQ5Gai03a svurT36dgRx3Bc9OjXWO7eeoxXgn2bsu9BTBuUkTkqgllup7p2ypEc7XMhNF9WYZZXG2 uR/0epLdV/Yz7TvCyiaLcFKuNvE9kTcVYrEGpWDdfeynzfwfjUKiluOzM1cupXs4vOQi 3hmA== 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:references:cc :to:from:subject; bh=aaIRfynaECFvUZ1cArx8yO0jRYm6vdUK2I2QiDMWSYQ=; b=lzVCIT/gyM2Y1xaUfAiZhaHjfEGpHqBzrIsV4/wX+wea44lQwm7F+Ezv79NO2fwv15 IXBFVxDZxW7+QAmadahL9TMBSf3CXdrkQYRJcB4PlSbZm+NiJllcBA+Q5mIoabdobX70 vZsR3btE06NSCZvKHlzhm8cFuItlysUxqkeeWJN1uDLHGP38sIm8l8bNQRCq/yZhTa/K 4Kum6Yvg54KHLSPxqLG/UWBCjpKu8j6iRAneaozfIkRXs/jz/LbOQqQhigHzHisolmSy hFFW9Stbw37+emOEYcAogDK6ObluKv7xY8JeXgrRZXqRnhX7Y80a/4LLeHITfrElRtxD wbWQ== 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 s17si3750425edd.576.2021.05.01.00.51.44; Sat, 01 May 2021 00:52:07 -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 S231707AbhEAHvK (ORCPT + 99 others); Sat, 1 May 2021 03:51:10 -0400 Received: from pegase2.c-s.fr ([93.17.235.10]:49317 "EHLO pegase2.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229510AbhEAHvJ (ORCPT ); Sat, 1 May 2021 03:51:09 -0400 X-Greylist: delayed 1108 seconds by postgrey-1.27 at vger.kernel.org; Sat, 01 May 2021 03:51:09 EDT Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4FXLXP5GqRz9sRr; Sat, 1 May 2021 09:31:49 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 9846q1DQgH85; Sat, 1 May 2021 09:31:49 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4FXLXP49fWz9sRq; Sat, 1 May 2021 09:31:49 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C91938B76F; Sat, 1 May 2021 09:31:48 +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 0LOx1gJ0iR8h; Sat, 1 May 2021 09:31:48 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6F8F68B763; Sat, 1 May 2021 09:31:47 +0200 (CEST) Subject: Re: [PATCH 1/3] lib: early_string: allow early usage of some string functions From: Christophe Leroy 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> <1929b3a8-f882-c930-4b99-10c6a8f127c7@csgroup.eu> Message-ID: Date: Sat, 1 May 2021 09:31:47 +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: <1929b3a8-f882-c930-4b99-10c6a8f127c7@csgroup.eu> 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 à 10:50, Christophe Leroy a écrit : > > > Le 30/04/2021 à 10:47, Christophe Leroy a écrit : >> >> >> 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 > > In fact, should be like in prom_init today: > > #ifdef __EARLY_STRING_ENABLED >     if (dsize >= count) >         return count; > #else >     BUG_ON(dsize >= count); > #endif Thinking about it once more, this BUG_ON() is overkill and should be avoided, see https://www.kernel.org/doc/html/latest/process/deprecated.html Therefore, something like the following would make it: if (dsize >= count) { WARN_ON(!__is_defined(__EARLY_STRING_ENABLED)); return count; } > >> >> >>> + >>> +    dest += dsize; >>> +    count -= dsize; >>> +    if (len >= count) >>> +        len = count-1; >>> +    memcpy(dest, src, len); >>> +    dest[len] = 0; >>> +    return res; >>> +} >>> +EXPORT_SYMBOL(strlcat); >>> +#endif >>> +