Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp955166pxf; Thu, 8 Apr 2021 17:43:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQvRNNkstZl8zGilVkIGa8ovVuCWuSjySZR7sQ20vtF7MQ6Lt+u07frAAUuTIo7Dgl6YCy X-Received: by 2002:a17:907:94c3:: with SMTP id dn3mr13871264ejc.280.1617928984220; Thu, 08 Apr 2021 17:43:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617928984; cv=none; d=google.com; s=arc-20160816; b=Tp/QdgoXF8hUAXf2EV8Bdy7OBAuNMbK61kVxsF5sS6JppVl6qdJikJcZYhMNfqyc/t bQG3TgOX3Jta/LCoqwJaB6gLdz3+R+8V4L2dZbQr0L+H3X1jSErgsHNkUIpC6O8KP+sf aim0w6lPifX8NZv7E7jJY054YMx4UaSFQQEOgCuV3oIuwXwgOSNKQ1oE1TyV5uqilF/s WryyGAOwGILaUf9+KhSXUHt+cE0gZmqepOPGwyQ+Y5JCWF6qVJk6Jg4RfjlpZlM37uoP j3uXpEeukRRUUHHU5blEUZFPPUn1sdT9eWk0gm1EbeD+svlPk4OUFa9VHSDmqbrZJUbi ySZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:from:subject:cc:to:message-id:date; bh=AScJUiZahozGHbq5xIoF1FsE8Or63qJww1erSO1BbTc=; b=dlQD2YiJbEHPoXwwRqB1B2s2fyKj9Z8lJ64ZDNvIrkSW3lIE8IP/Bg2o8AjNdHFqia Cij/8n4W0iXr537Xg/CVNQQvvu0F+pcoDnvAM5pR98ywlbhbIfgeRnvlCS3wayIso8Nu 6ZqDn5DZaXoNo22RY0VQ/PTYxXPeJtmjERNn7mWH7zHQYKVEFEIEAHzriKaa2fzovhHy CLdiPKn3omHR1sv826Q9Yh95cymVhdjfx61rySpxe2HolBOgATp+k8dPk0NMLyrzlCBD VEIUSoqb5kx8TgbJn6CFIsxqGQdPEJWgkdPQYbC6oU8ukROegiuVDJVLajKqkd8HO5C4 jafQ== 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 z19si879280edc.604.2021.04.08.17.42.41; Thu, 08 Apr 2021 17:43:04 -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 S233059AbhDIAlk (ORCPT + 99 others); Thu, 8 Apr 2021 20:41:40 -0400 Received: from shards.monkeyblade.net ([23.128.96.9]:60892 "EHLO mail.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232426AbhDIAli (ORCPT ); Thu, 8 Apr 2021 20:41:38 -0400 Received: from localhost (unknown [IPv6:2601:601:9f00:477::3d5]) by mail.monkeyblade.net (Postfix) with ESMTPSA id 4C7D24D249441; Thu, 8 Apr 2021 17:41:26 -0700 (PDT) Date: Thu, 08 Apr 2021 17:41:22 -0700 (PDT) Message-Id: <20210408.174122.1793350393067698495.davem@davemloft.net> To: decui@microsoft.com Cc: kuba@kernel.org, kys@microsoft.com, haiyangz@microsoft.com, sthemmin@microsoft.com, wei.liu@kernel.org, liuwe@microsoft.com, netdev@vger.kernel.org, leon@kernel.org, andrew@lunn.ch, bernd@petrovitsch.priv.at, rdunlap@infradead.org, linux-kernel@vger.kernel.org, linux-hyperv@vger.kernel.org Subject: Re: [PATCH v3 net-next] net: mana: Add a driver for Microsoft Azure Network Adapter (MANA) From: David Miller In-Reply-To: References: <20210408225840.26304-1-decui@microsoft.com> <20210408.164618.597563844564989065.davem@davemloft.net> X-Mailer: Mew version 6.8 on Emacs 27.1 Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (mail.monkeyblade.net [0.0.0.0]); Thu, 08 Apr 2021 17:41:26 -0700 (PDT) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dexuan Cui Date: Fri, 9 Apr 2021 00:24:51 +0000 >> From: David Miller >> Sent: Thursday, April 8, 2021 4:46 PM >> ... >> > +struct gdma_msg_hdr { >> > + u32 hdr_type; >> > + u32 msg_type; >> > + u16 msg_version; >> > + u16 hwc_msg_id; >> > + u32 msg_size; >> > +} __packed; >> > + >> > +struct gdma_dev_id { >> > + union { >> > + struct { >> > + u16 type; >> > + u16 instance; >> > + }; >> > + >> > + u32 as_uint32; >> > + }; >> > +} __packed; >> >> Please don't use __packed unless absolutely necessary. It generates >> suboptimal code (byte at a time >> accesses etc.) and for many of these you don't even need it. > > In the driver code, all the structs/unions marked by __packed are used to > talk with the hardware, so I think __packed is necessary here? It actually isan't in many cases, check with and without the __packed directive and see if anything chasnges. > Do you think if it's better if we remove all the __packed, and add > static_assert(sizeof(struct XXX) == YYY) instead? e.g. > > @@ -105,7 +105,8 @@ struct gdma_msg_hdr { > u16 msg_version; > u16 hwc_msg_id; > u32 msg_size; > -} __packed; > +}; > +static_assert(sizeof(struct gdma_msg_hdr) == 16); This won't make sure the structure member offsets are what you expect. I think you'll have to go through the structures one-by-one by hand to figure out which ones really require the __packed attribute and which do not. Thank you.