From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C98A043E32; Wed, 10 Apr 2024 09:32:14 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 52B01402CF; Wed, 10 Apr 2024 09:32:14 +0200 (CEST) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 6A73C4029E; Wed, 10 Apr 2024 09:32:12 +0200 (CEST) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id 25B23B335; Wed, 10 Apr 2024 09:32:12 +0200 (CEST) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id 18EF8B246; Wed, 10 Apr 2024 09:32:12 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.3 Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 80D78B384; Wed, 10 Apr 2024 09:32:10 +0200 (CEST) Message-ID: <28162ea3-7679-49a5-ac44-869718d32f53@lysator.liu.se> Date: Wed, 10 Apr 2024 09:32:10 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 0/4] RFC samples converting VLA to alloca To: =?UTF-8?Q?Morten_Br=C3=B8rup?= , Tyler Retzlaff , Stephen Hemminger , techboard@dpdk.org Cc: dev@dpdk.org, Bruce Richardson , Thomas Monjalon References: <20231107193220.GA15232@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <1712250913-1977-1-git-send-email-roretzla@linux.microsoft.com> <98CBD80474FA8B44BF855DF32C47DC35E9F379@smartserver.smartshare.dk> <20240407100306.36c9688f@hermes.local> <20240408152703.GA25804@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <98CBD80474FA8B44BF855DF32C47DC35E9F380@smartserver.smartshare.dk> Content-Language: en-US From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F380@smartserver.smartshare.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On 2024-04-08 17:53, Morten Brørup wrote: >> From: Tyler Retzlaff [mailto:roretzla@linux.microsoft.com] >> Sent: Monday, 8 April 2024 17.27 >> >> For next technboard meeting. >> >> On Sun, Apr 07, 2024 at 10:03:06AM -0700, Stephen Hemminger wrote: >>> On Sun, 7 Apr 2024 13:07:06 +0200 >>> Morten Brørup wrote: >>> >>>>> From: Mattias Rönnblom [mailto:hofors@lysator.liu.se] >>>>> Sent: Sunday, 7 April 2024 11.32 >>>>> >>>>> On 2024-04-04 19:15, Tyler Retzlaff wrote: >>>>>> This series is not intended for merge. It insteat provides examples >>>>> of >>>>>> converting use of VLAs to alloca() would look like. >>>>>> >>>>>> what's the advantages of VLA over alloca()? >>>>>> >>>>>> * sizeof(array) works as expected. >>>>>> >>>>>> * multi-dimensional arrays are still arrays instead of pointers to >>>>>> dynamically allocated space. this means multiple subscript syntax >>>>>> works (unlike on a pointer) and calculation of addresses into >>>>> allocated >>>>>> space in ascending order is performed by the compiler instead of >>>>> manually. >>>>>> >>>>> >>>>> alloca() is a pretty obscure mechanism, and also not a part of the C >>>>> standard. VLAs are C99, and well-known and understood, and very >>>>> efficient. >>>> >>>> The RFC fails to mention why we need to replace VLAs with something else: >>>> >>>> VLAs are C99, but not C++; VLAs were made optional in C11. >>>> >>>> MSVC doesn't support VLAs, and is not going to: >>>> https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support- >> arriving-in-msvc/#variable-length-arrays >>>> >>>> >>>> I dislike alloca() too, and the notes section in the alloca(3) man page >> even discourages the use of alloca(): >>>> https://man7.org/linux/man-pages/man3/alloca.3.html >>>> >>>> But I guess alloca() is the simplest replacement for VLAs. >>>> This RFC patch series opens the discussion for alternatives in different >> use cases. >>>> >>> >>> The other issue with VLA's is that if the number is something that can be >> externally >>> input, then it can be a source of stack overflow bugs. That is why the Linux >> kernel >>> has stopped using them; for security reasons. DPDK has much less of a >> security >>> trust domain. Mostly need to make sure that no data from network is being >>> used to compute VLA size. >>> >> >> Looks like we need to discuss this at the next techboard meeting. >> >> * MSVC doesn't support C11 optional VLAs (and never will). >> * alloca() is an alternative that is available on all platforms/toolchain >> combinations. >> * it's reasonable for some VLAs to be turned into regular arrays but it >> would be unsatisfactory to be stuck waiting discussions of defining new >> constant expression macros on a per-use basis. > > We must generally stop using VLAs, for many reasons. What reasons would that be? And which of those reasons are not also reasons to stop using alloca(). > The only available 1:1 replacement is alloca(), so we have to accept that. > > If anyone still cares about improvements, we can turn alloca()'d arrays into regular arrays after this patch series. > > Alternatives to VLAs are very interesting discussions, but let's not stall MSVC progress because of it! > What is this supposed to mean? Finding alternatives to VLAs are required to make progress of MSVC support in DPDK. >> * there is resistance to using alloca() vs VLA so my proposal is to >> change only the code that is built to target windows. > > I would prefer to get rid of them all, so the CI can build with -Wvla to prevent them from being introduced again. > Not a strong preference. > On the other hand, the CI's MSVC builds will catch them if used for a Windows target. > And limiting to Windows code reduces the amount of work, so that's probably the most realistic solution. >