Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2008809pxf; Sat, 3 Apr 2021 07:53:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8OOabBMJvfXu0jtVHTtXCkLmsD6ouaWgPEv7GkzzxtHVOmlP2acfVtqQgJgTCG5++1L2A X-Received: by 2002:a17:906:3c18:: with SMTP id h24mr19089123ejg.435.1617461580314; Sat, 03 Apr 2021 07:53:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617461580; cv=none; d=google.com; s=arc-20160816; b=Tgy0u3BvPXerCKpPXMDsytIewuipbpDvccpF+AllHabuxIpgDs/nQwI3+ZNGMHhkg6 lzg4puJMURfocT08YwdZkOOem2880jYENXTKzms/ZYhCBL7ai/7nTB3d5CkFAZgeoGml NRo+SwilrBGqyq009zcHC6j/EAbKyrj42xAwfCCsUpBG2VwDlhkB1kZXd2TiUAKW4X7a nyDASsYDkCIpQSQ/19VbY1qEN8D1XLNISu/AmHQxabwbgD3Lgg/mUnG8GbSmG2fQdgcE dx1S0bP1rOs+mS0WUyIyFLXw+zsC61DyUL7w9IVnlb+kzfk2wEY/R20tPoRYoiSEPGW/ 3iQQ== 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:message-id:subject:cc:to:from:date; bh=lOscgHiZ4zhAoic4t5x0wULqfoKgzqu24gNzcQT6ubc=; b=HQ4Imt4IRTCA1NYRUR3DiaWl9kurJDXlBzxO6/CSKlPiSLSCFfszvQFU/UeTGo5R+/ CK+Z5cguWwQaJYIyE0zRGJpRI26zXwhSLPbdeHChLwyZT8xhVtNMwsEFCiHNtTJFINGt oDIQfYkpMywjaYQOCUK2u2mmL/5FlgvSVOTO34cH4aYEsM2gwFXiEKYf7r38wL8/jFpo rhPwXbZRYkx3z9okuaOZw8eastVuM7h8TBBPIWDirudiqR6voL+44ksREklWAI9DF06F 7mp+rvV4hiutnlLwjzE5CWXNOe8IVBlZ2PMsq/IB1xhl+CXbq/mwFj3Ih1EgbwmkvPY5 9/jA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k25si8779991ejq.186.2021.04.03.07.52.37; Sat, 03 Apr 2021 07:53:00 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=gentoo.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236724AbhDCOv6 (ORCPT + 99 others); Sat, 3 Apr 2021 10:51:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236380AbhDCOv6 (ORCPT ); Sat, 3 Apr 2021 10:51:58 -0400 Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A048C0613E6; Sat, 3 Apr 2021 07:51:55 -0700 (PDT) Date: Sat, 3 Apr 2021 15:51:48 +0100 From: Sergei Trofimovich To: "Elliott, Robert (Servers)" Cc: Arnd Bergmann , "Martin K. Petersen" , "John Paul Adrian Glaubitz" , Don Brace - C33706 , "linux-ia64@vger.kernel.org" , "storagedev@microchip.com" , linux-scsi , "jszczype@redhat.com" , Scott Benesh , Scott Teel , "thenzl@redhat.com" , Linux Kernel Mailing List Subject: Re: [PATCH v2 3/3] hpsa: add an assert to prevent from __packed reintroduction Message-ID: <20210403155148.0f5c94ff@sf> In-Reply-To: References: <20210330071958.3788214-1-slyfox@gentoo.org> <20210330071958.3788214-3-slyfox@gentoo.org> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2 Apr 2021 14:40:39 +0000 "Elliott, Robert (Servers)" wrote: > It looks like ia64 implements atomic_t as a 64-bit value and expects atomic_t > to be 64-bit aligned, but does nothing to ensure that. > > For x86, atomic_t is a 32-bit value and atomic64_t is a 64-bit value, and > the definition of atomic64_t is overridden in a way that ensures > 64-bit (8 byte) alignment: > > Generic definitions are in include/linux/types.h: > typedef struct { > int counter; > } atomic_t; > > #define ATOMIC_INIT(i) { (i) } > > #ifdef CONFIG_64BIT > typedef struct { > s64 counter; > } atomic64_t; > #endif > > Override in arch/x86/include/asm/atomic64_32.h: > typedef struct { > s64 __aligned(8) counter; > } atomic64_t; > > Perhaps ia64 needs to take over the definition of both atomic_t and atomic64_t > and do the same? I don't think it's needed. ia64 is a 64-bit arch with expected natural alignment for s64: alignof(s64)=8. Also if my understanding is correct adding __aligned(8) would not fix use case of embedding locks into packed structs even on x86_64 (or i386): $ cat a.c #include #include typedef struct { unsigned long long __attribute__((aligned(8))) l; } lock_t; struct s { char c; lock_t lock; } __attribute__((packed)); int main() { printf ("offsetof(struct s, lock) = %lu\nsizeof(struct s) = %lu\n", offsetof(struct s, lock), sizeof(struct s)); } $ x86_64-pc-linux-gnu-gcc a.c -o a && ./a offsetof(struct s, lock) = 1 sizeof(struct s) = 9 $ x86_64-pc-linux-gnu-gcc a.c -o a -m32 && ./a offsetof(struct s, lock) = 1 sizeof(struct s) = 9 Note how alignment of 'lock' stays 1 byte in both cases. 8-byte alignment added for i386 in https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=bbf2a330d92c5afccfd17592ba9ccd50f41cf748 is only as a performance optimization (not a correctness fix). Larger alignment on i386 is preferred because alignof(s64)=4 on that target which might make atomic op span cache lines that leads to performance degradation. -- Sergei