From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5D80C433E2 for ; Sun, 6 Sep 2020 16:45:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 653C12080A for ; Sun, 6 Sep 2020 16:45:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599410722; bh=bbQaHGEB+MEO+DEaG2y/EKFYlV4kuJWL/RVT0ZCxmy8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=n0r/UwrYmcwelnsGY/xRtoFtmisHINYvK3aXf0tNOoRxuhWe0HUPcUhJCB7FxOdH5 HAcE/bvBUc1mNt8wgGQ0vrK7ird6v5sG+ZNZy8I4LVYy3hbTa39xu9uXrE8FNe62C/ MHTtTwcUrHIYQa57uJt2Fzd+K7P5mRbcfE3r7Hzw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726410AbgIFQpU (ORCPT ); Sun, 6 Sep 2020 12:45:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:37152 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbgIFQpT (ORCPT ); Sun, 6 Sep 2020 12:45:19 -0400 Received: from kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com (unknown [163.114.132.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CBCEF207BB; Sun, 6 Sep 2020 16:45:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599410718; bh=bbQaHGEB+MEO+DEaG2y/EKFYlV4kuJWL/RVT0ZCxmy8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=M7BAIIrPt0kaFHrjAMIy/qMvYtWpUPCVAKAHPrdXVaJpl48Ivtwf5tq7UEgqqfyz6 jEX7DLR3w8G0nq38bRwJjD+YY9WiPJKIBb65UaT7H9jJzTIyHeBgJLwPbEFXbUTkVw LUUoypBztbuwApjM5lMNExKWdT3LWLtDedJ0D4zI= Date: Sun, 6 Sep 2020 09:45:16 -0700 From: Jakub Kicinski To: Shay Agroskin Cc: Maciej Fijalkowski , "Jubran, Samih" , Andrew Lunn , "davem@davemloft.net" , "netdev@vger.kernel.org" , "Woodhouse, David" , "Machulsky, Zorik" , "Matushevsky, Alexander" , "Bshara, Saeed" , "Wilson, Matt" , "Liguori, Anthony" , "Bshara, Nafea" , "Tzalik, Guy" , "Belgazal, Netanel" , "Saidi, Ali" , "Herrenschmidt, Benjamin" , "Kiyanovski, Arthur" , "Dagan, Noam" Subject: Re: [PATCH V2 net-next 1/4] net: ena: ethtool: use unsigned long for pointer arithmetics Message-ID: <20200906094516.2f8ea69c@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> In-Reply-To: References: <20200819134349.22129-1-sameehj@amazon.com> <20200819134349.22129-2-sameehj@amazon.com> <20200819141716.GE2403519@lunn.ch> <91c86d46b724411d9f788396816be30d@EX13D11EUB002.ant.amazon.com> <20200826153635.GA51212@ranger.igk.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Sun, 6 Sep 2020 13:47:13 +0300 Shay Agroskin wrote: > Maciej Fijalkowski writes: > > I don't want to stir up the pot, but do you really need the > > offsetof() of > > each member in the stats struct? Couldn't you piggyback on > > assumption that > > these stats need to be u64 and just walk the struct with > > pointer? > > > > struct ena_ring *ring; > > int offset; > > int i, j; > > u8 *ptr; > > > > for (i = 0; i < adapter->num_io_queues; i++) { > > /* Tx stats */ > > ring = &adapter->tx_ring[i]; > > ptr = (u8 *)&ring->tx_stats; > > > > for (j = 0; j < ENA_STATS_ARRAY_TX; j++) { > > ena_safe_update_stat((u64 *)ptr, > > (*data)++, &ring->syncp); > > ptr += sizeof(u64); > > } > > } > > > > I find this as a simpler and lighter solution. There might be > > issues with > > code typed in email client, but you get the idea. > > > >> > >> of course we need to convert the stat_offset field to be in 8 > >> bytes resolution instead. > >> > >> This approach has a potential bug hidden in it. If in the > >> future > >> someone decides to expand the "ena_stats_tx" struct and add a > >> field preceding cnt, > >> cnt will no longer be the beginning of the struct, which will > >> cause a bug." > >> > >> Therefore, if you have another way to do this, please share > >> it. Otherwise I'd > >> rather leave this code as it is for the sake of robustness. > >> > >> > > >> > Andrew > > Hi all, > > We tried to implement your suggestion, and found that removing the > stat_offset > field causes problems that are challenging to solve. > Removing stat_offset introduces a requirement that the statistics > in a stat > strings array (check [1] for example) and stat variables struct > (check [2] for > example) must be in the same order. > This requirement is prone to future bugs that might be challenging > to locate. > We also tried to unify the array and struct creation by > using X macros. At the moment this change requires more time and > effort by us > and our customers need this code merged asap. > > [1] https://elixir.bootlin.com/linux/v5.9- > rc3/source/drivers/net/ethernet/amazon/ena/ena_ethtool.c#L71 > [2] https://elixir.bootlin.com/linux/v5.9- > rc3/source/drivers/net/ethernet/amazon/ena/ena_netdev.h#L232 > > (This message was sent before but didn't seem to get into the > mailing list. Apologies if you got it twice) Divide the offset by 8, cast &ring->tx_stats to u64 * (without referencing cnt). That should be fine.