Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp126960ima; Tue, 5 Feb 2019 19:33:37 -0800 (PST) X-Google-Smtp-Source: AHgI3IYmZw/S2PDjHDykfUkVRzCGskLuVEiXh5RrcXviPzbZakhG6zniK5TOwoAO0ntYshrOFWIl X-Received: by 2002:a65:60c2:: with SMTP id r2mr7760623pgv.393.1549424017816; Tue, 05 Feb 2019 19:33:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549424017; cv=none; d=google.com; s=arc-20160816; b=0zpXlQJRgVOCgE0/3YpySnY63EoM/VlLy7bpzVQWOTxlAfCK44AlOD4QD/pLI73MMU 5AwrGOeZFHrvzPLYK4rX+MYGqIE65Bzmu+IuCksTcK9z8J4n5UqqlVORyZp9oQTrnfAR noiC4JiD8mW/zwMKDa/aqVjNsiQ+UfqAhjlo2cz4BJlqukjm3LsFHP6y8z4ZT55dMFmf CZvydIiCH/rx4vE2dTYIkBMo8IpwaxA377rwxzxZZBEuv5nisGLa+JONwE4esYSMbgxX 5O4ynlCuQhqQw8y5ocxhrDDyfyNTQCtwwuN/j5mhAj7eMzKQiJkGJszu4IQA6jZPYDJm 4FzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=T6rorQDMO3FDb0/kjyAPfQvlsHjOV41wgtRdzX0XMGI=; b=u7GJ+un42RZddVbqS9WNlURrtgWNMbRxg1rWMbvtMJANugviVHwELr+/p1czkyiIfm ryJsKYhj/+tKqvAcv0t5qNGl1ebFO/AdSt/B7TrNc64akBiksSWMdiAd7EawEeKmO1fB T+X1Qjakdrr3KNA9HrCQhMDwXE6+reW2+SWjMp178LUJLWoRvgB3hGQrbaZjvt3iGQqL 93/YKNeFPqhVowEj7TczE3RipesqXWqMX5fAlc5yxb9iSXfdYUwecCQSU0aB2QR2BqxQ /ZyTQBPEiEM375SRJLA4PwUPfqJp0EbTT2gVXhlb2efwLWw8SbVkudZOwJeevnUwUGzY 9rjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Nhh1iuSM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si4403271pgf.22.2019.02.05.19.33.22; Tue, 05 Feb 2019 19:33:37 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Nhh1iuSM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727681AbfBFDZZ (ORCPT + 99 others); Tue, 5 Feb 2019 22:25:25 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:33598 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725981AbfBFDZZ (ORCPT ); Tue, 5 Feb 2019 22:25:25 -0500 Received: by mail-pl1-f194.google.com with SMTP id z23so2485893plo.0; Tue, 05 Feb 2019 19:25:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=T6rorQDMO3FDb0/kjyAPfQvlsHjOV41wgtRdzX0XMGI=; b=Nhh1iuSMVdYkzzkh05BgjKsvzGATXBO8cstzzW+TvS5D51sFHhLx/1pIe2NWlO92LI mr094lm+XBq5uNBfSRI8Eck6T+GDuB20GLEyB3VvH9VHejbkTQCtFUSrZzEI9C9gaena aoddeUXnwZ7ym79TOVNrvfeZtpK6r0fe9qlc+y4uJ+j1KnT9tu++lAiZpjNQWtU2dREA Un/h+ZkXl4m4zCODLiUOpCkj7TCRmYaPiWjLFS3NmWfCuCB15EG4E5ZMqepMwY06gWxl pMCqd13U3M/A5I2Lxi7hOyIEXB06ZXniYxDrdHKJ1Pa0y4v1rb7ximZgcPO11PHkPrmm Z2UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T6rorQDMO3FDb0/kjyAPfQvlsHjOV41wgtRdzX0XMGI=; b=XfdWTV8ArkBXlQPaa+fJBi0zXWQJ+fHbkEBrjQaSqWnz646MujnhrVzxT8lQL/5DuY ySwePeqoIjv2pekWSSuCtDkeRaEksAVgoaweRQuOD5Kgqos2gsEtMCkZ+NkOF9UKgknY Qx1Cchs7NsrOUHIFb0wAXcCKFjcOjRJnRj/o1PD7RzCWqKmnnLLZc81ARsw5GmqIBOZM QpFPeTtVn1I9waRRkPMF+HgQE5ZkfqyGir8/PIiKG7f8yWyAR7Q/+2afvQO4YE1XVTGU LxwubUyVkLL/ErYf00cIMHG/lzLxqTj08mE3jjXfB44Mza0R6xEuAiRFBNDUDlI+FxHs tNjw== X-Gm-Message-State: AHQUAuY1CEtSEEhXphoPi2RJgpWGezOzBG+vpR0uIqYwZtkPG3sMJmo8 ZOarBPMGISabKLUiNz6vRQGdxjyjFqA= X-Received: by 2002:a17:902:42e4:: with SMTP id h91mr8621445pld.18.1549423524646; Tue, 05 Feb 2019 19:25:24 -0800 (PST) Received: from Paul-HP (174-17-117-135.phnx.qwest.net. [174.17.117.135]) by smtp.gmail.com with ESMTPSA id p13sm5478279pgs.89.2019.02.05.19.25.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 19:25:24 -0800 (PST) Date: Tue, 5 Feb 2019 20:25:22 -0700 From: Paul Zimmerman To: Joe Perches Cc: Eric Dumazet , Heiner Kallweit , David Miller , linux-kernel@vger.kernel.org, linux-netdev@vger.kernel.org Subject: Re: [PATCH v2 2/2] r8169: Avoid pointer aliasing Message-Id: <20190205202522.2ab2ea40430e817d4f01cc4e@gmail.com> In-Reply-To: <9e4332bf41d5d58a4fa6cf138fc9ea3b2f9a488f.camel@perches.com> References: <20190205192733.b4bd98988d1e4695f740d445@gmail.com> <9e4332bf41d5d58a4fa6cf138fc9ea3b2f9a488f.camel@perches.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 05 Feb 2019 18:52:18 -0800, Joe Perches wrote: > On Tue, 2019-02-05 at 19:27 -0700, Paul Zimmerman wrote: >> On Tue, 2019-02-05, Joe Perches wrote: >>> On Tue, 2019-02-05 at 12:04 -0800, Eric Dumazet wrote: >>> > On 02/05/2019 10:42 AM, Joe Perches wrote: >>> > > It's declared after a pointer so it is already is 2 byte aligned. >>> > > >>> > > A lot of drivers wouldn't work otherwise. >>> > >>> > Maybe these drivers are only used on arches where this does not matter. >>> >>> Possible. >>> >>> I had only grepped through the sources looking for >>> declarations using: >>> >>> $ git grep -B1 '\[ETH_ALEN\];' -- '*.c' | grep -A1 '\*' >>> >>> It's quite a few files in net/ too btw. >>> >>> I still think adding __align() is unnecessary here unless >>> it follows something like a bool or a u8. >> >> Um, guys, this is practically C-101. >> >> From C99, 6.7.2.1: >> >> > 13/ Within a structure object, the non-bit-field members and the units in >> > which bit-fields reside have addresses that increase in the order in which >> > they are declared. A pointer to a structure object, suitably converted, >> > points to its initial member (or if that member is a bit-field, then to the >> > unit in which it resides), and vice versa. There may be unnamed padding >> > within a structure object, but not at its beginning. >> >> AFAIK there is no such language in the spec regarding variable layout on >> the stack. So Joe, you are totally off-base here. > > We're not talking about the spec, see the void * arithmetic > bit, we're talking about what gcc and clang actually do. Sorry, I see I was a bit unclear. In an earlier message, which I neglected to quote, you said: > It's declared after a pointer so it is already is 2 byte aligned. > A lot of drivers wouldn't work otherwise. But it's declared after a pointer *on the stack* (local variable), not in a structure. I was trying to say that there is nothing in the C spec that says that local variables have any kind of ordering guarantee, unlike struct members. And I have never seen any kernel code that relies on the ordering of local variables to work correctly. I used to work a lot with low-level C/assembly code, and I know for a fact that GCC does not lay out stack variables in the same order that they are declared. -- Paul