From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from fhigh-a3-smtp.messagingengine.com (fhigh-a3-smtp.messagingengine.com [103.168.172.154]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5CD761A9B46; Thu, 16 Oct 2025 06:53:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.154 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760597594; cv=none; b=iqgV0Lzun7RWaXc04/Dq5yA0vq03oR//LNJHRa0cW4M9wlwGM4XMVRMsifoU964+ydn682lMvkUIqDBe9GtVX4V2OAsQSmrvqvi14C6hj0BUiCwAlBS062R1masRDYmvMp+F4kXfFRZbt1mFzhfWoFWQnusjjrHWhl9uO/f5aSQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760597594; c=relaxed/simple; bh=LoP0iL2fgdFZyWRft6p0C1mJ+sXum2DzJhkgo80tJwY=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=GgGH6LMVLXSsvIOPMMQfIHrdp+GV75Kl5h82Ujr/B1ez/yyO8q+J7GoCRf35IPp6YEKwTIWYxCegN72A4BAEuKl/qRC+5B4v3VE3iX2HhMmrrVA70PtA+FO6J3Rdf9N26jWdTDqUDYk1c1lJ90G83p0TMaCx6ZM45995te3BZ6E= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org; spf=none smtp.mailfrom=linux-m68k.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=MshjixAm; arc=none smtp.client-ip=103.168.172.154 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux-m68k.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="MshjixAm" Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4C05014000F4; Thu, 16 Oct 2025 02:53:09 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-04.internal (MEProxy); Thu, 16 Oct 2025 02:53:09 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t= 1760597589; x=1760683989; bh=tcUBI5yvDagqARx1NRhoV/Xb73Hae3sjMcC zbp2ZYMI=; b=MshjixAmEDWJtMGKvrmtBxn8dNwDRLg8fCulAR/XGo3Gsrfuynv pV/lk8YPlC2PY56rMG3RyG5WNNZDL5vTRTVyHg5rzDJc9adoIiGP+DBpYPWnBT/r gZ1uIp/EFCIaMHdB5ncUSmXl4MD5Tub7GGKEcuCWT80VWFxKoGGJGuRS2M2ETIRw /iKPKDlp6pUHYEf3LUUGHYarSNsQos2MLapnv/S3nvCM99QmFlJAmuJKA9y9kCp7 R/5yxrJFHn7siUrXblYkGGNI/pmTinXisoBUZj0aKNa2C3I+wAQnx8zbrYPWyskM jQOF1d1SI4s6gd9T/W3wgWQmiKjQvbfEU4w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdduvdehiedvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevufgjkfhfgggtsehttdertddttddvnecuhfhrohhmpefhihhnnhcuvfhh rghinhcuoehfthhhrghinheslhhinhhugidqmheikehkrdhorhhgqeenucggtffrrghtth gvrhhnpeelueehleehkefgueevtdevteejkefhffekfeffffdtgfejveekgeefvdeuheeu leenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehfth hhrghinheslhhinhhugidqmheikehkrdhorhhgpdhnsggprhgtphhtthhopedufedpmhho uggvpehsmhhtphhouhhtpdhrtghpthhtohepuggrvhhiugdrlhgrihhghhhtrdhlihhnuh igsehgmhgrihhlrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggu rdhorhhgpdhrtghpthhtohepfihilhhlsehkvghrnhgvlhdrohhrghdprhgtphhtthhope grkhhpmheslhhinhhugidqfhhouhhnuggrthhiohhnrdhorhhgpdhrtghpthhtohepsgho qhhunhdrfhgvnhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtoheptghorhgsvghtsehlfi hnrdhnvghtpdhrtghpthhtohepmhgrrhhkrdhruhhtlhgrnhgusegrrhhmrdgtohhmpdhr tghpthhtoheprghrnhgusegrrhhnuggsrdguvgdprhgtphhtthhopehlihhnuhigqdhkvg hrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i58a146ae:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 16 Oct 2025 02:53:05 -0400 (EDT) Date: Thu, 16 Oct 2025 17:53:05 +1100 (AEDT) From: Finn Thain To: David Laight cc: Peter Zijlstra , Will Deacon , Andrew Morton , Boqun Feng , Jonathan Corbet , Mark Rutland , Arnd Bergmann , linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Geert Uytterhoeven , linux-m68k@vger.kernel.org, linux-doc@vger.kernel.org Subject: Re: [RFC v3 1/5] documentation: Discourage alignment assumptions In-Reply-To: <20251015145332.260eebe6@pumpkin> Message-ID: <29188dc5-32a3-28f9-b488-26cca713e070@linux-m68k.org> References: <76571a0e5ed7716701650ec80b7a0cd1cf07fde6.1759875560.git.fthain@linux-m68k.org> <20251014112359.451d8058@pumpkin> <20251015145332.260eebe6@pumpkin> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Wed, 15 Oct 2025, David Laight wrote: > > There are several separate alignments: > - The alignment the cpu needs, for most x86 instructions this is 1 byte [1]. > Many RISC cpu require 'word' alignment (for some definition of 'word'). > A problematic case is data that crosses page boundaries. > - The alignment the compiler uses for structure members; returned by _Alignof(). > m68k only 16bit aligns 32bit values. > - The 'preferred' alignment returned by __alignof__(). > 32bit x86 returns 8 for 64bit types even though the ABI only 4-byte aligns them. > - The 'natural' alignment based on the size of the item. > I'd guess that 'complex double' (if supported) may only be 8 byte aligned. > Those distinctions could be useful in a discussion about memory efficiency. But this document is concerned with avoiding a performance penalty -- it's entirely unconcerned with over-alignment and memory waste. Hence, "aligned" is used as shorthand for "naturally aligned". The ambiguity in this document (and my proposed change) stems from using the word architecture to cover ABI, platform, CPU, ISA etc. I can improve upon that. > What normally matters is the ABI alignment for structure members. > If you mark anything 'packed' the compiler will generate shifts and masks (etc) > to get working code. > Taking the address of an item in a packed structure generates a warning > for very good reason. > I believe the problem with 'packed' is already covered in this document. > [1] I've fallen foul of gcc deciding to 'vectorise' a loop and then having > it crash because the buffer address was misaligned. > Nasty because the code worked in initial testing and I expected the loop > (32bit adds of a buffer) to work fine even when misaligned. > I think that pitfall is already discussed also, along with a remedy. There is also this, ... for standard structure types you can always rely on the compiler to pad structures so that accesses to fields are suitably aligned (assuming you do not cast the field to a type of different length). So it seems to be fairly comprehensive but I may be missing something (?)