Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2110610pxf; Sat, 27 Mar 2021 02:57:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcP9x2qhszTpmKE4z3lxEwdw9femxCgXzhagzm8193BraQ6pGAoP8Rqeso6NnMYZTU4DzC X-Received: by 2002:a17:906:170d:: with SMTP id c13mr19018322eje.491.1616839030250; Sat, 27 Mar 2021 02:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616839030; cv=none; d=google.com; s=arc-20160816; b=bXrK0YE1l4E9CA5pHlgVQUg4ALbBHakP2ng81JByEZmCjF5GoY2Fr9qAxoSa+6FBK8 03VLbPcputQk8DJuqqDnky8YworvHi4uG0eRZfDG5/NCG61v4KLyBL2LcRAEUflNVJrV wu7JSKAebh3IWNHHOL7p8BQGNtLtJ67R50R1t96pv6TdXciQ9n/6wkWIcUMGwX0eMUzM FxwEQXSlqzG/FVV6QuvKVgveQkFh7oU46VyxncuHUyaXS2+piKOgUUbsZCVY2yXwdVCK n+bJL/gq7qtj6xRIv+ELv6+DtTwUfqlcIv/xf3kFz9ig8xnuyUpONlRUO4HcGW5zDQv8 qPvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=ei4Zq2qQr5wPT1q7tW3R31IHQU2GQmJWy+Z1ULLx9Gg=; b=RlET15FUHUNz5G3FlSJLEiR/4Blogw00BMSUkDCY6eiCG4LADSBXyTMmERn/UD0UKH m9+1dDjCK6BPJdXeYcm0hF88cFHshwXei0Fi4NLwVn4CXq+HgKDlZyCLtPMuSgSPoR/h 6+s9C1JNcwQnRMFY/FsgWSQ6LmU9AOaAUlMel5wGw+XJKDr869oVR10A/MZRdN4Sh6Uq +8mYlXqfoxmq13HSpgGPJUwjkXhB5DLOpGg+dprY5R8yldQ/YLnL/MqBIO73Wc61U1a3 QgtGiVDHTQhPWbYdHP4c/jyjd3YD3ZD4D16b9CwUmh1KO3zweNUJx1T3ZmcexowvcRiJ IKag== 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 mh2si8709810ejb.107.2021.03.27.02.56.47; Sat, 27 Mar 2021 02:57:10 -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 S231553AbhC0Jxl (ORCPT + 99 others); Sat, 27 Mar 2021 05:53:41 -0400 Received: from mail-vk1-f177.google.com ([209.85.221.177]:38596 "EHLO mail-vk1-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231403AbhC0Jxg (ORCPT ); Sat, 27 Mar 2021 05:53:36 -0400 Received: by mail-vk1-f177.google.com with SMTP id d2so1738484vke.5; Sat, 27 Mar 2021 02:53:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ei4Zq2qQr5wPT1q7tW3R31IHQU2GQmJWy+Z1ULLx9Gg=; b=OkLeY0cPw8mDKwazvUX0w6b+iWhu1urtVNqJZOVYXwdr2dPj72hOz3d37xbfRIozVt rVEleMCPDw9hZTI/5kC/e8H4pprbTEJBu2gMUcVVf0ejC2un5Ob5LHrkESxsQ41KWzXl 7HHoIq9z27U7X3jex9IjFmvAqq99BT81C0o1ze2iOklX/DFh4SDBVCL5eKne+csWYU4s gI4b9sFssbFuCT4f9kZ/PuFFTzWCPNmN0Gj6D8CNfvHhrVq3w6OQ91UtGenJlbVw79Kj cdjTrx48MKpi9HlIsBHPS/jAcPOZMLrHlnYK85EKt2dKtIS72Pbh0654B9eV5BPaBtLK uIxg== X-Gm-Message-State: AOAM532pxuYKGaHXH8mBTRWGddo/600+9xjxIzn51Nji8cN4kp+xqL3Z l4ledvo6+LB7yhBuS9xR60M3f4cmBUlKee3gCEA= X-Received: by 2002:a1f:b689:: with SMTP id g131mr10365672vkf.6.1616838815501; Sat, 27 Mar 2021 02:53:35 -0700 (PDT) MIME-Version: 1.0 References: <20210325223119.3991796-1-anthony.l.nguyen@intel.com> <20210325223119.3991796-2-anthony.l.nguyen@intel.com> In-Reply-To: From: Geert Uytterhoeven Date: Sat, 27 Mar 2021 10:53:23 +0100 Message-ID: Subject: Re: [PATCH net 1/4] virtchnl: Fix layout of RSS structures To: "Samudrala, Sridhar" Cc: anthony.l.nguyen@intel.com, Norbert Ciosek , "David S. Miller" , Jakub Kicinski , netdev , sassmann@redhat.com, Konrad Jankowski , Mateusz Palczewski , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Samudrala, On Fri, Mar 26, 2021 at 11:45 PM Samudrala, Sridhar wrote: > On 3/26/2021 1:06 AM, Geert Uytterhoeven wrote: > > On Thu, Mar 25, 2021 at 11:29 PM Tony Nguyen wrote: > > From: Norbert Ciosek > > > > Remove padding from RSS structures. Previous layout > > could lead to unwanted compiler optimizations > > in loops when iterating over key and lut arrays. > > > > From an earlier private conversation with Mateusz, I understand the real > > explanation is that key[] and lut[] must be at the end of the > > structures, because they are used as flexible array members? > > > > Fixes: 65ece6de0114 ("virtchnl: Add missing explicit padding to structures") > > Signed-off-by: Norbert Ciosek > > Tested-by: Konrad Jankowski > > Signed-off-by: Tony Nguyen > > > > --- a/include/linux/avf/virtchnl.h > > +++ b/include/linux/avf/virtchnl.h > > @@ -476,7 +476,6 @@ struct virtchnl_rss_key { > > u16 vsi_id; > > u16 key_len; > > u8 key[1]; /* RSS hash key, packed bytes */ > > - u8 pad[1]; > > }; > > > > VIRTCHNL_CHECK_STRUCT_LEN(6, virtchnl_rss_key); > > @@ -485,7 +484,6 @@ struct virtchnl_rss_lut { > > u16 vsi_id; > > u16 lut_entries; > > u8 lut[1]; /* RSS lookup table */ > > - u8 pad[1]; > > }; > > > > If you use a flexible array member, it should be declared without a size, > > i.e. > > > > u8 key[]; > > > > Everything else is (trying to) fool the compiler, and leading to undefined > > behavior, and people (re)adding explicit padding. > > This header file is shared across other OSes that use C++ that doesn't support > flexible arrays. So the structures in this file use an array of size 1 as a last > element to enable variable sized arrays. I don't think it is accepted practice to have non-Linux-isms in include/*linux*/avf/virtchnl.h header files. Moreover, using a size of 1 is counter-intuitive for people used to Linux kernel development, and may lead to off-by-one errors in calculation of sizes. If you insist on ignoring the above, this definitely deserves a comment next to the member's declaration. Gr{oetje,eeting}s, Geert -- Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds